updating data from datagridview
-
hello every body, i use a datagrid view bounded to a datasource, but i can't update the changes happens in it. although, i've added the insert, update & delete queries i also use a dataset with a tableAdapter . and this what iam doing in the onSaveButton_Click: try { dataGridView1.EndEdit(); this.visitorTableAdapter.Update(this.omvDataSet.visitor); omvDataSet.AcceptChanges(); MessageBox.Show("Changes saved successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } so, what is the right solution to accomplish what i want. Regards
-
hello every body, i use a datagrid view bounded to a datasource, but i can't update the changes happens in it. although, i've added the insert, update & delete queries i also use a dataset with a tableAdapter . and this what iam doing in the onSaveButton_Click: try { dataGridView1.EndEdit(); this.visitorTableAdapter.Update(this.omvDataSet.visitor); omvDataSet.AcceptChanges(); MessageBox.Show("Changes saved successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } so, what is the right solution to accomplish what i want. Regards
-
hi, what's wrong now? code looks good, but you don't need to
.AcceptChanges()
because.Update()
does it for you. ;-) kind regardsok i removed .AcceptChanges() now i tried to delete then i had this exception: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows. regards
-
ok i removed .AcceptChanges() now i tried to delete then i had this exception: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows. regards
-
Hi, are you sure you filled all commands of DataAdapter? There are InsertCommand, UpdateCommand, DeleteCommand and SelectCommand (last is filled by constructor, normally). ;-) King regards
Hi, yes i did filled these commands by the dataset designer but, i found that i have to add them into the properties window by myself and now it's working. thanks for your help, i really appreciate it. Regards