用C#把Textbox中填写的数据插入到Access数据库中的代码怎么写?

2024-11-01 13:33:00
推荐回答(1个)
回答1:

不知道你主要是缺少哪些,时间比较紧张给你一段查询的代码,插入基本是把sql语句修改了,执行一块修正下。和SQL类似
string dbname = "car.accdb";
string sqlText = "select * from testTable";
string connstr = " Provider= Microsoft.ACE.OLEDB.12.0;Persist Security Info=false;Jet OLEDB:Database Password=hatz;Data Source =F:\\car.accdb";
OleDbConnection oldbconn = new OleDbConnection(connstr);
label9.Text = label2.Text = DateTime.Now.TimeOfDay.ToString();
oldbconn.Open();
System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(sqlText, oldbconn);
System.Data.DataSet ds = new DataSet();
da.Fill(ds, "ds");
dataGridView1.DataSource = ds.Tables[0];
oldbconn.Close();