feedback on DataAdapter.Update

adshocker

Well-known member
Joined
Jun 30, 2007
Messages
180
Programming Experience
Beginner
hi all,

i think i'm beginning to understand how the dataadapter.update method is being used here in ado.net... but i need some verifications first.

here's is my scenario..

at form load, i retrieve data from my database using of course, a connection, an adapter, and a dataset.
sample source:

VB.NET:
Dim connection As New SqlConnection("connection string here")
Dim adapter As New SqlDataAdapter("SELECT ID, username, password FROM accounts", connection)

Dim update As New SqlCommand("UPDATE accounts SET username = @username, password = @password WHERE ID = @ID", connection)

update.Parameters.Add("@id", SqlDbType.Int, 4, "id")
update.Parameters.Add("@username", SqlDbType.VarChar, 15, "username")
update.Parameters.Add("@password", SqlDbType.VarChar, 15, "password")

adapter.UpdateCommand = update

dim mydataset as new dataset

adapter.fill(mydataset, "accounts")
datagrid.datasource = mydataset

here is a sample screen after form loaded and data was binded to my datagrid.

screnbefore.jpg


then, i try to edit some data in my datagrid like this...

screenafter.jpg


then i put this code in a save button for example.

VB.NET:
adapter.Update(mydataset, "accounts")

now, based on the steps i have here, if i click the save button, will it update the changes made to my database so the next time the form loads, it will display records equal to that of the second screen?

i just want to clarify, based on the images, i changed data on 2 rows... will my update command automatically update both rows for me or do i need to do something else?

thanks...
 
Last edited:
I've just found my notes from this problem. To throw a spanner in the works, it only ever happened to me if the row in the grid was the only row. If there were rows there already, and I was adding a new one, it was OK. If no rows existed and I was adding the "first one", EndEdit wouldn't work (well wouldn't save the row when .update was called)
 
I've just found my notes from this problem. To throw a spanner in the works, it only ever happened to me if the row in the grid was the only row. If there were rows there already, and I was adding a new one, it was OK. If no rows existed and I was adding the "first one", EndEdit wouldn't work (well wouldn't save the row when .update was called)

Iif you can reproduce it on a form for me, then I can look into it. Bear in mind that there is a strange bug of this type when working with related data.. Specifically that child records will be lost when EndEdit is called on the parent
 
Back
Top