Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C#
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);
Posted
Updated 3-Oct-11 20:24pm

1 solution

C#
sda.Update((ds1,table_name1);
is this a immediate line after
C#
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
C#
sda
and
C#
ds1
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..
 
Share this answer
 
Comments
bsb25 4-Oct-11 3:52am    
sry..i didnt understand what u were trying to explain.The code u tried is also missing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900