Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataAdapter.Update() dosen't work !
 

DataAdapter.Update() dosen't work !

There is a DataGridView which is bounded to the Northwind database.
I use the following procedure to save all changes that are made to DataSet, but it doesn't save new rows.



PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnUpdate.Click
Try
IfmyDataSet11.HasChangesThen
Me.BindingContext(myDataSet11,"Employees").EndCurrentEdit()
SqlDataAdapter1.Update(myDataSet11)
myDataSet11.AcceptChanges()
EndIf
CatcherrObjAsException
MsgBox(errObj.Message.ToString())
myDataSet11.RejectChanges()
EndTry
EndSub


Afshin_Zavar  Wednesday, February 04, 2009 2:40 PM
The code looks reasonable.
Several things you can try

a) confirm that the dataset actually has changes,
myDataSet11.HasChanges(DataRowState.Added)
b) may not have changes until after you call EndCurrentEdit to add a new row in the view to the table.
consider moving that line before the call to HasChanges.

This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to mark the replies as answers if they help.
  • Marked As Answer byAfshin_Zavar Saturday, February 07, 2009 9:20 PM
  •  
Mark.Ashton - MSFT  Saturday, February 07, 2009 1:58 AM
The code looks reasonable.
Several things you can try

a) confirm that the dataset actually has changes,
myDataSet11.HasChanges(DataRowState.Added)
b) may not have changes until after you call EndCurrentEdit to add a new row in the view to the table.
consider moving that line before the call to HasChanges.

This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to mark the replies as answers if they help.
  • Marked As Answer byAfshin_Zavar Saturday, February 07, 2009 9:20 PM
  •  
Mark.Ashton - MSFT  Saturday, February 07, 2009 1:58 AM

You can use google to search for other answers

Custom Search

More Threads

• Detecting mouse click location for a DataGridViewCell
• DataBinding Problem?
• 2 DataGridView Questions
• Datagridview - Specific color on one row
• Connection to Sql Server 2000 on Lan
• Databind textboxes
• datagridview problem setting col types
• Changing DataGridView.Enabled hangs application
• Synchronise data from a client to a sql server database
• How to combine two Columns in DataGrid ?