You are on page 1of 5

Cho cc bn lu lm ri shell.php mi gh qua din n lp trnh mi chng trnh dng cho vic nghn cu khoa hc m khng ra chn .

.Mnh xin php c vit mt bi c g sai st mong mi ngi thng cm. Mnh s hng dn mi ngi cch to kt ni access vi C#.Mi ngi phi c kin thc cht t v C# nha. Mi ngi c xong 3 tap .pdf s hiu cc cu lnh cua mnh di nha mnh s khoobg gii thch nha y l c s d liu cho cc bn thc hnh Mnh dng Microsoft Visual Studio 2008 Cc bn vo C# chn windows forms application

Mnh s hng dn cc bn lam vi d m thy gio mnh cho lm to chc nng duyt nh hnh di y c th ni y l bt c bn.

lm c nh trn cc bn Chn toolbox cc bn dng label,TextBox , ComboBox, Button.Ri bi gi ti phn lp trnh,to ra mt lp nh sau

Trong Lp class.cs
using using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb; System.Data;

namespace ketnoiAccess { class ct1201 { OleDbConnection con = new OleDbConnection(); public ct1201() { string ketnoi; if (con.State == ConnectionState.Closed) { ketnoi = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=quanlydiem.mdb"; con.ConnectionString = ketnoi; con.Open(); } } public DataSet Getdataset (string tenbang) { OleDbDataAdapter da = new OleDbDataAdapter(); OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); string sql = "select *from"+tenbang; cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = sql; da.SelectCommand = cmd;

da.Fill(ds, tenbang); return ds; } } } Ri mi ngi tip tc ti File Form nha: using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace ketnoiAccess { public partial class CT1201 : Form { public CT1201() { InitializeComponent(); } ct1201 a = new ct1201(); int vitri = 0; DataTable SV = new DataTable(); private void CT1201_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); ds = a.Getdataset("sinhvien"); vitri = 0; SV=ds.Tables["sinhvien"]; Gandulieu(SV, vitri); } void Gandulieu(DataTable dt, int vitri) { DataRow drw; drw = dt.Rows[vitri]; masv.Text = drw["Masv"].ToString();//masv ten TextBox M SV hten.Text=drw["tensv"].ToString(); diachi.Text = drw["Diachi"].ToString(); dienthoai.Text=drw["dienthoai"].ToString(); malop.Text = drw["Malop"].ToString(); ngaysinh.Text=drw["ngaysinh"].ToString(); vtri.Text = "vitri" + Convert.ToString(vitri + 1) + "/" + SV.Rows.Count.ToString(); } private void button1_Click(object sender, EventArgs e) { vitri += 1;

if (vitri > SV.Rows.Count - 1) vitri = 0; Gandulieu(SV, vitri); } private void button2_Click(object sender, EventArgs e) { vitri -= 1; if (vitri < 0) vitri = SV.Rows.Count - 1; Gandulieu(SV, vitri); } } } V y l kt qu

You might also like