Adapter









How do I use Adapter
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ClassDAL.cs Copy
16         public DataTable GetTable(string sql)
17         {
18             SqlConnection con = GetConnect();
19             SqlDataAdapter ad = new SqlDataAdapter(sql, con);
20             DataTable dt = new DataTable();
21             ad.Fill(dt);
22             return dt;
23             con.Close();
24         }
File name: FormBaoCao.cs Copy
27         public void loadCmb()
28         {
29             SqlConnection con = dal.GetConnect();
30             con.Open();
31             SqlCommand cm = new SqlCommand("Select *from Lop", con);
32             SqlDataAdapter da = new SqlDataAdapter(cm);
33             DataTable dt = new DataTable();
34             da.Fill(dt);
35             this.cmbMaLop.DisplayMember = "MaLop";
36             this.cmbMaLop.ValueMember = "MaLop";
37             this.cmbMaLop.DataSource = dt;
38         }
File name: FormBaoCao.cs Copy
40         private void btnLoc_Click(object sender, EventArgs e)
41         {
42             SqlConnection con = dal.GetConnect();
43             con.Open();
44             string sql = "select *from SinhVien where MaLop=@MaLop";
45             SqlDataAdapter da = new SqlDataAdapter(sql, con);
46             da.SelectCommand.Parameters.AddWithValue("@MaLop", cmbMaLop.SelectedValue.ToString());
47             DataTable dt = new DataTable();
48             da.Fill(dt);
49             crBaoCao cr = new crBaoCao();
50             ConnectionInfo crConnectionInfo = new ConnectionInfo();
51             crConnectionInfo.ServerName = "Ty-PC";
52             crConnectionInfo.DatabaseName = "CNPM_1";
53             crConnectionInfo.UserID = "sa";
54             crConnectionInfo.Password = "04091990";
55             TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
56             foreach (CrystalDecisions.CrystalReports.Engine.Table table in cr.Database.Tables)
57             {
58                 TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
59                 crTableLogonInfo.TableName = table.Name;
60                 crTableLogonInfo.ConnectionInfo = crConnectionInfo;
61                 crTableLogonInfos.Add(crTableLogonInfo);
62                 table.ApplyLogOnInfo(crTableLogonInfo);
63
64             }
65             crvHocKyHocPhan.LogOnInfo = crTableLogonInfos;
66             cr.SetDataSource(dt);
67             ParameterValues a = new ParameterValues();
68             ParameterDiscreteValue b = new ParameterDiscreteValue();
69             b.Value = cmbMaLop.SelectedValue.ToString();
70             a.Add(b);
71             cr.DataDefinition.ParameterFields["txtMaLop"].ApplyCurrentValues(a);
72             crvHocKyHocPhan.ReportSource = cr;
73             crvHocKyHocPhan.Show();
74         }
File name: FormKHGD.cs Copy
20         private void FormKHGD_Load(object sender, EventArgs e)
21         {
22             // TODO: This line of code loads data into the 'cNPM_1DataSet5.KhoiLop' table. You can move, or remove it, as needed.
23             this.khoiLopTableAdapter.Fill(this.cNPM_1DataSet_KhoiLop.KhoiLop);
24             // TODO: This line of code loads data into the 'cNPM_1DataSet4.HocKy' table. You can move, or remove it, as needed.
25             this.hocKyTableAdapter.Fill(this.cNPM_1DataSet_HocKy.HocKy);
26             dgvKHGD.DataSource = business.ShowData("KeHoachGiangDay");
27         }
File name: FormKhoiLop.cs Copy
20         private void FormKhoiLop_Load(object sender, EventArgs e)
21         {
22             // TODO: This line of code loads data into the 'cNPM_1DataSet3.TrinhDoDaoTao' table. You can move, or remove it, as needed.
23             this.trinhDoDaoTaoTableAdapter.Fill(this.cNPM_1DataSet_TrinhDoDaoTao.TrinhDoDaoTao);
24             // TODO: This line of code loads data into the 'cNPM_1DataSet2.HeDaoTao' table. You can move, or remove it, as needed.
25             this.heDaoTaoTableAdapter.Fill(this.cNPM_1DataSet_HeDaoTao.HeDaoTao);
26             dgvKhoiLop.DataSource = business.ShowData("KhoiLop");
27         }
File name: FormLop.cs Copy
20         private void FormLop_Load(object sender, EventArgs e)
21         {
22             // TODO: This line of code loads data into the 'cNPM_1DataSet8.GiangVien' table. You can move, or remove it, as needed.
23             this.giangVienTableAdapter.Fill(this.cNPM_1DataSet_GiangVien.GiangVien);
24             // TODO: This line of code loads data into the 'cNPM_1DataSet7.KhoiLop' table. You can move, or remove it, as needed.
25             this.khoiLopTableAdapter.Fill(this.cNPM_1DataSet_KhoiLop.KhoiLop);
26             dgvLop.DataSource = business.ShowData("Lop");
27
28         }
File name: FormNhomHocPhan.cs Copy
20         private void FormNhomHocPhan_Load(object sender, EventArgs e)
21         {
22             // TODO: This line of code loads data into the 'cNPM_1DataSet11.GiangVien' table. You can move, or remove it, as needed.
23             this.giangVienTableAdapter.Fill(this.cNPM_1DataSet11.GiangVien);
24             // TODO: This line of code loads data into the 'cNPM_1DataSet10.KeHoachGiangDay' table. You can move, or remove it, as needed.
25             this.keHoachGiangDayTableAdapter.Fill(this.cNPM_1DataSet10.KeHoachGiangDay);
26             // TODO: This line of code loads data into the 'cNPM_1DataSet9.HocPhan' table. You can move, or remove it, as needed.
27             this.hocPhanTableAdapter.Fill(this.cNPM_1DataSet9.HocPhan);
28             dgvNhomHocPhan.DataSource= business.ShowData("NhomHocPhan");
29         }
File name: FormQuanLyDiem.cs Copy
23         private void FormQuanLyDiem_Load(object sender, EventArgs e)
24         {
25             // TODO: This line of code loads data into the 'cNPM_1DataSet4.HocKy' table. You can move, or remove it, as needed.
26             this.hocKyTableAdapter.Fill(this.cNPM_1DataSet4.HocKy);
27
28         }
File name: FormQuanLyDiem.cs Copy
29         public void loadCmbMaNhomHP(string MaHK)
30         {
31             SqlConnection con = dal.GetConnect();
32             con.Open();
33             SqlCommand cm = new SqlCommand("Select MaNhomHP from NhomHocPhan,KeHoachGiangDay where NhomHocPhan.MaKHGD=KeHoachGiangDay.MaKHGD and KeHoachGiangDay.MaHK='"+MaHK+"'", con);
34             SqlDataAdapter da = new SqlDataAdapter(cm);
35             DataTable dt = new DataTable();
36             da.Fill(dt);
37             this.cmbMaNhomHP.DisplayMember = "MaNhomHP";
38             this.cmbMaNhomHP.ValueMember = "MaNhomHP";
39             this.cmbMaNhomHP.DataSource = dt;
40         }
File name: FormSinhVien.cs Copy
20         private void FormSinhVien_Load(object sender, EventArgs e)
21         {
22             // TODO: This line of code loads data into the 'cNPM_1DataSet6.Lop' table. You can move, or remove it, as needed.
23             this.lopTableAdapter.Fill(this.cNPM_1DataSet_Lop.Lop);
24             dgvSinhVien.DataSource = business.ShowData("SinhVien");
25         }

Download file with original file name:Adapter

Adapter 126 lượt xem

Gõ tìm kiếm nhanh...