Danh mục

Hướng Dẫn Thực Hành Winform - phần 5 ADO.NET (tt)

Số trang: 8      Loại file: pdf      Dung lượng: 334.57 KB      Lượt xem: 11      Lượt tải: 0    
Jamona

Hỗ trợ phí lưu trữ khi tải xuống: 4,000 VND Tải xuống file đầy đủ (8 trang) 0

Báo xấu

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu hướng dẫn thực hành winform - phần 5 ado.net (tt), công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Hướng Dẫn Thực Hành Winform - phần 5 ADO.NET (tt)Xây d ng ph n m m hư ng i tư ng GVHD: Tr n Anh Dũng HƯ NG D N TH C HÀNH TU N 5 Ch : ADO.NET (tt) Ph n 2: Các thao tác k t n i ADO.NET s d ng c u trúc dòng l nh v i namespace System.Data. (K t n i v i Database SQL Server)1. Thi t k CSDL SQL Server như sau:a. T o databse v i tên DBHOCSINH, thi t k các table sau: HOCSINH STT Tên trư ng Ki u d li u Ghi chú 1 MaHS Nvarchar(20) PrimaryKey 2 TenHS Nvarchar(100) 3 NgaySinh Datetime 4 DiaChi Nvarchar(255) 5 DTB Real 6 MaLop Nvarchar(20) ForeignKey (tham chi u n Lop(MaLop) LOP STT Tên trư ng Ki u d li u Ghi chú 1 MaLop Nvarchar(20) PrimaryKey 2 TenLop Nvarchar(100) 3 SiSo smallint2. T o project m i: Thi t k l i Form “K t n i CSDL SQL Server” như màn hình sau:Xây d ng ph n m m hư ng i tư ng GVHD: Tr n Anh Dũng Source code l p frmConnectionusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace QLHocSinh{ public partial class frmConnection : Form { //Khai báo bi n thành ph n public string sServerName = ; public string sDatabaseName = ; public string sUser = ; public string sPass = ; public frmConnection() { InitializeComponent(); } private void frmConnection_Load(object sender, EventArgs e) { txtServerName.Focus(); } private void cmdExit_Click(object sender, EventArgs e) { this.Close(); } private bool KiemTraDLHopLe() { if (txtServerName.Text.Trim().Length == 0)Xây d ng ph n m m hư ng i tư ng GVHD: Tr n Anh Dũng { MessageBox.Show(Chưa nh p tên máy ch ., Thong bao loi, MessageBoxButtons.OK, MessageBoxIcon.Stop); return false; } if (txtDBName.Text.Trim().Length == 0) { MessageBox.Show(Chưa nh p tên CSDL., Thong bao loi, MessageBoxButtons.OK, MessageBoxIcon.Stop); return false; } return true; } private void cmdConnect_Click(object sender, EventArgs e) { if (!KiemTraDLHopLe()) return; sServerName = txtServerName.Text.Trim(); sDatabaseName = txtDBName.Text.Trim(); sUser = txtUser.Text.Trim(); sPass = txtPass.Text.Trim(); frmHocSinh frm = new frmHocSinh(); //Ki m tra k t n i CSDL if (!frm.connect(sServerName, sDatabaseName, sUser, sPass)) { MessageBox.Show(K t n i n máy ch không thành công., Thong bao loi, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } MessageBox.Show(K t n i n máy ch thành công., Thong bao, MessageBoxButtons.OK, MessageBoxIcon.Information); frm.Show(); this.Hide(); } }}Xây d ng ph n m m hư ng i tư ng GVHD: Tr n Anh DũngThi t k form nh p thông tin h c sinh như sau: K t qu màn hình khi ch y: DataGridViewXây d ng ph n m m hư ng i tư ng GVHD: Tr n Anh Dũng k t n i v i CSDL SQL Server dùng namespace: using System.Data.SqlClient;Source code l p Màn hình nh p thông tin h c sinh:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace QLHocSinh{ public partial class frmHocSinh : Form { private SqlConnection connection; private SqlDataAdapter adapter; private DataSet dataSet; private SqlCommand command; private string maHS, tenHS, diachi, malop; private float dtb; private DateTime ngaysinh; public frmHocSinh() { InitializeComponent(); } public bool connect(string sServerName, string sDBName, string sUser, str ...

Tài liệu được xem nhiều: