Updating Information

Rainbow123

New member
Joined
Feb 9, 2013
Messages
2
Programming Experience
Beginner
Hey!

I'm having problem's saving/adding data to my database, this is the code I'm using ;

Dim objRow As DataRow
objDataAdapter.Fill(objDataSet, "Admin")
objRow = objDataSet.Tables("Admin").NewRow
objRow.Item("Name") = txtName.Text
objRow.Item("Address") = txtAddress.Text
objDataSet.Tables("Admin").Rows.Add(objRow)
objDataSet.AcceptChanges()
objDataAdapter.Update(objDataSet, "Admin")


I'm not getting any errors when I debug - but the information doesn't store in my database file. Any ideas on where I'm going wrong?
 
Get rid of the call to AcceptChanges. AcceptChanges is called after all the changes have been saved but there's no need to call it explicitly when using a data adapter because Update will call it implicitly.
 
Dim objRow As DataRow
objRow = objDs.Tables("Admin").NewRow()
objRow.Item("Name") = txtName.Text
objRow.Item("Address") = txtAddress.Text
objDs.Tables("Admin").Rows.Add(objRow)
objDA.Update(objDs, "Admin")

Im using this code now instead but getting this error
"Update requires a valid InsertCommand when passed DataRow collection with new rows."
any ideas?!
 
As the error message suggests, your data adapter has to have its InsertCommand set if it needs to insert records. Likewise the UpdateCommand must be set if you need to update records and the DeleteCommand must be set if you need to delete records. You can set them yourself or, if certain conditions are met, let a command builder do it for you. The following thread of mine includes an example of each:

Retrieving and Saving Data in Databases
 
Back
Top