dataAdapter update problem
-
Hi, I have some strange problems with the update of a dataadapter. First, I read a row in a table, through a dataset :
da = New SqlDataAdapter(sql, conn) ds = New DataSet da.Fill(ds, "MyTable") da.SelectCommand.CommandText = "select * from address" Dim sqlBuilder As SqlCommandBuilder = New SqlCommandBuilder(da) da.InsertCommand = sqlBuilder.GetInsertCommand() da.DeleteCommand = sqlBuilder.GetDeleteCommand() da.UpdateCommand = sqlBuilder.GetUpdateCommand() ta = ds.Tables("MyTable") pka(0) = ta.Columns("address_id") ta.PrimaryKey = pka dim dr As DataRow dr = ta.Rows.Find(1) 'get the address with id 1
Then I update a field :dr("country_id") = system.dbnull.value
and now I commit the change :da.update(ds)
But changes are not reflected in the database.... The update command doesn't work with this update. If country_id value is not null, it works... I precise that country_id is nullable in the DB. Thanks for any help. Best regards. Arthur -
Hi, I have some strange problems with the update of a dataadapter. First, I read a row in a table, through a dataset :
da = New SqlDataAdapter(sql, conn) ds = New DataSet da.Fill(ds, "MyTable") da.SelectCommand.CommandText = "select * from address" Dim sqlBuilder As SqlCommandBuilder = New SqlCommandBuilder(da) da.InsertCommand = sqlBuilder.GetInsertCommand() da.DeleteCommand = sqlBuilder.GetDeleteCommand() da.UpdateCommand = sqlBuilder.GetUpdateCommand() ta = ds.Tables("MyTable") pka(0) = ta.Columns("address_id") ta.PrimaryKey = pka dim dr As DataRow dr = ta.Rows.Find(1) 'get the address with id 1
Then I update a field :dr("country_id") = system.dbnull.value
and now I commit the change :da.update(ds)
But changes are not reflected in the database.... The update command doesn't work with this update. If country_id value is not null, it works... I precise that country_id is nullable in the DB. Thanks for any help. Best regards. ArthurSee some senario we can't predict that user will give correct, valid data. So i recommand you to define an update,delete command by yourself and execute the command. And assign this defined queary to respective delete,update command of your data adapter Sreejith Nair [ My Articles ]
-
Hi, I have some strange problems with the update of a dataadapter. First, I read a row in a table, through a dataset :
da = New SqlDataAdapter(sql, conn) ds = New DataSet da.Fill(ds, "MyTable") da.SelectCommand.CommandText = "select * from address" Dim sqlBuilder As SqlCommandBuilder = New SqlCommandBuilder(da) da.InsertCommand = sqlBuilder.GetInsertCommand() da.DeleteCommand = sqlBuilder.GetDeleteCommand() da.UpdateCommand = sqlBuilder.GetUpdateCommand() ta = ds.Tables("MyTable") pka(0) = ta.Columns("address_id") ta.PrimaryKey = pka dim dr As DataRow dr = ta.Rows.Find(1) 'get the address with id 1
Then I update a field :dr("country_id") = system.dbnull.value
and now I commit the change :da.update(ds)
But changes are not reflected in the database.... The update command doesn't work with this update. If country_id value is not null, it works... I precise that country_id is nullable in the DB. Thanks for any help. Best regards. ArthurI dont know whether my suggestion is right. first check the entries are null or not. If null update with ''. ie blank. does this answer the question. sreejiths answer is a good way but working with insert,delete and update query in data adapter is not that easy.
(Behind the truth)
Anandah