-
February 16th, 2012, 04:08 AM
#1
Fail update database from DataGridView
I am working at winforms project and i have a datagridview from which i am trying to update a database from it when the user changes something. Here is the code:
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["EbosPr.Properties.Settings.Database1ConnectionString1"].ConnectionString);
SqlCommand scmd = new SqlCommand("Select * From CustCalls ", conn);
SqlDataAdapter sda = new SqlDataAdapter(scmd);
sda.Fill(ds);
DataTable dt = ds.Tables[0];
this.dataGridView1.BindingContext[dt].EndCurrentEdit();
SqlCommandBuilder myBuilder = new SqlCommandBuilder(sda);
myBuilder.GetUpdateCommand();
sda.UpdateCommand = myBuilder.GetUpdateCommand();
sda.Update(dt);
The above code doesnt update the database. Any idea?
-
February 17th, 2012, 01:35 AM
#2
Re: Fail update database from DataGridView
Did you check the below?
Before to your Update command ou have to give
DataGridView1.EndEdit();
And after to your update command you have to give
sda.Acceptchanges
Last edited by MAHEY; February 17th, 2012 at 01:39 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|