使用datagridview更新数据库. [英] Update database using datagridview.

查看:88
本文介绍了使用datagridview更新数据库.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个代码,该代码使用datagridview(Windows窗体)更新数据库.
我能够将数据加载到表单中,但无法更新它们.
我尝试使用以下代码进行更新,但无法正常工作.
任何人都可以指出代码中的问题,或者我应该进行哪些更改才能使代码正常工作?

I am writing a code which updates the database using datagridview(windows forms).
I am able to load the data into the forms,but am not able to update the same.
I tried using the below code to update,but its not working.
Can anyone point the issue within the code or what changes should i do to make the code working?

string con = "Data Source=01HW306775\\SQLEXPRESS;Integrated Security=TRUE;";
string query = "Select * from Customers";
sda = new SqlDataAdapter(query, con);
SqlCommandBuilder sc1 = new SqlCommandBuilder(sda);
DataSet ds1 = new DataSet();
DataTable db1 = new DataTable();
sda.Fill(ds1);
dataGridView1.DataSource = ds1.Tables[0];
sda.Update((ds1,table_name1);

推荐答案

sda.Update((ds1,table_name1);

dataGridView1.DataSource = ds1.Tables[0];  

...之后的直接行吗? ??

如果是的话,没有任何区别.您正在更新表中的相同数据.相反,您应该使

...???

if yes, it doest make any difference. you are updating the same data back in the table. rather u should make

sda

ds1

成为班级的私有成员,并且在您选择的任何需要进行gridview的事件中,也可以调用基于某些条件包含这些行的单独思路.

希望这会有所帮助.

and private members of class and in any of the events of your choice on gridview or you can call separate menthod which contains these lines based on some condition.

hope this helps..


这篇关于使用datagridview更新数据库.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆