如何在C#中更新或刷新与Ms访问连接的数据网格视图 [英] how to update or refresh datagrid view connected with Ms-access in C#
问题描述
我已经将数据库连接到 Ms-access 2010(.mdb)
与 C#
然后我想要在 datagrid
视图中显示,以下是我用于保存的代码或插入数据
hi i have already connected the database in Ms-access 2010(.mdb)
with C#
then i want to display it in datagrid
view , here is the code that i used to save or insert the data
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into VMS(PlateNo,JobCardNo,Model,DateIn,Status,PartList,PurchNo,PurchDate,Remark)" + "values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "')";
cmd.Connection = mycon;
mycon.Open();
cmd.ExecuteNonQuery();
mycon.Close();
这个工作正常,问题是当我保存在MS访问中保存的新数据时,没有更新或显示在datagridview中。任何帮助将不胜感激
this works right, the problem is when i save new data it save in MS- access but it will not updated or displayed in the datagridview. any help will be appreciated
推荐答案
这是在插入一些数据后更新datagridview的最佳方法。
This is the best way To update your datagridview after inserting some data.
数据集sDs = new DataSet();
sAdapter.Fill(sDs,T1);
sTable = sDs。表[T1];
dataGridView1.DataSource = sDs.Tables [T1]; code>
dataGridView1.DataSource = sDs.Tables["T1"];
这篇关于如何在C#中更新或刷新与Ms访问连接的数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!