如何使用oledbadapter更新访问数据库 [英] How to update the access DB with oledbadapter
本文介绍了如何使用oledbadapter更新访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友们......
我在一个单独的类文件中写了一个函数,它返回 Dataset 。此函数帮助我绑定datagridview。
Hi Friends...
I have a written a function in a separate class file which return Dataset. This function help me to bind the datagridview.
public DataSet dsreturn_edit(DataSet ds, String qry)
{
try
{
if (conn.State == ConnectionState.Closed)
{ conn.Open(); }
OleDbCommand itemcmd = new OleDbCommand(qry, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(itemcmd);
adapter.Fill(ds, "DailyData");
return ds;
}
catch (Exception ex)
{
MessageBox.Show("There was an error loading data to dataset. DETAIL: " + ex.ToString(), "My Application");
}
finally
{
conn.Close();
}
return ds;
}
在表单加载事件中我绑定Datagridview就像这样
In the form load event I am binding the Datagridview like this
BindingSource bs = new BindingSource();
DataSet ds = new DataSet();
bs.DataSource = dc.dsreturn(ds, "Select ID,FullName,Mobile,DOB,Gender,Status from Family").Tables[0];
dataGridView1.DataSource = bs;
我的要求是点击按钮更新datagridview。我需要像这样使用。
My requirement is to update the datagridview with a button click. I need to use like this.
adapter.Update(dataTable);
问题是,我不使用任何形式适配器对象。我的最终目的是更新数据库更新关键字
Problem is that, in the form i am not using any adapter object. My ultimate is to update the DB with Update Keyword
推荐答案
由于您已经在使用数据适配器来获取数据,因此您可以该适配器是表单的成员变量。
您可以在MSDN中使用此示例,以便为适配器创建选择和更新命令。
OleDbDataAdapter.UpdateCommand Property [ ^ ]
As you are already using a data adapter for getting your data, you can make that adapter a member variable of the form.
You can use this example from MSDN in order to create the select and update commands for the adapter.
OleDbDataAdapter.UpdateCommand Property[^]
这篇关于如何使用oledbadapter更新访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文