0

Plz help me out to resolve a conflict. I have made untiring efforts to resolve but coudln't. I have showed my data in gridivew now in windows forms now i want that when i make chages on the gridview using it like an excel sheet. These changes should also be reflected back in database. I have used this code.

da = new SqlDataAdapter(); 
cb = new SqlCommandBuilder(da); 
myGridView.DataSource = ds.Tables["UserDetails"]; 
ds.AcceptChanges(); da.Update(ds, "UserDetails"); 
con.Close();

what's wrong? how can i edit specific cell values.

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
2
Replies
6
Views
7 Years
Discussion Span
Last Post by __avd
0

Prepare connection, adapter, and builder object.

cn=new SqlConnection("put_connection_string_here");
da = new SqlDataAdapter("select * from tablename",cn); 
cb = new SqlCommandBuilder(da);

Fetch data from the database.

DataSet ds=new DataSet();
da.Fill(ds,"UserDetails");

myGridView.DataSource = ds.Tables["UserDetails"];

To update data.

da.Update(ds, "UserDetails");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.