问题描述
System.Data.OleDb.OleDbConnectionoleDbConnection1;ConnString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=db2.mdb";oleDbConnection1=newOleDbConnection(ConnString);stringmySQL="INSERTINTO购水记录(购水人,单位,桶数,金额,时间)VALUES('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+sum+"','"+CurrTime+"')";stringmySQL1="SELECT*FROM购水记录";OleDbCommandmyCommand=newOleDbCommand(mySQL,oleDbConnection1);DataSetDataSet1=newDataSet();oleDbConnection1.Open();OleDbDataReadermyReader=myCommand.ExecuteReader();OleDbDataAdapteroleDbDataAdapter1=newOleDbDataAdapter(mySQL1,oleDbConnection1);oleDbDataAdapter1.Fill(DataSet1,"购水记录");oleDbDataAdapter1.Update(DataSet1,"购水记录");dataGridView1.DataSource=DataSet1.Tables["购水记录"];oleDbDataAdapter1.Update(DataSet1,"购水记录");myReader.Close();oleDbConnection1.Close();在access中插入新记录后马上显示,新增记录能在dataGridView1中显示,但关闭程序在access中发现记录并没有写入。新手跪求请教~
解决方案
解决方案二:
OleDbCommandmyCommand=newOleDbCommand(mySQL,oleDbConnection1);OleDbDataReadermyReader=myCommand.ExecuteReader();你这根本就没用上啊,上面写的代码。
解决方案三:
有吧,照书打的~运行时添加新的记录可以马上显示(表中增加了一行并有正确数据)~ps:不小心打多了一次oleDbDataAdapter1.Update(DataSet1,"购水记录");