Problems with SQL command builder.

NicoVB

Well-known member
Joined
Jan 2, 2002
Messages
160
Location
Belgium
What are the reasons that a SQL command builder object doesnt build an update statement properly.

When I ask the commandtext that it created, it gives whole the string but the parameters dont have any values.

So I update nothing.

I have a primary key in my initial query: SELECT * FROM Table1 WHERE ID = 2 (this is one row)

Then I bind all the controls I need to change. When I change one value of and I click on UPDATE. It doesnt do anything, because he doesnt produce values for the parameters in the update query.

Any solution??
 
Hi,

Not sure exactly what you are doing, but if you are binding - for instance text boxes, and you are only editing one record you need to make sure that you finish the edit before trying to update the dataset otherwise the DataRowState property of the DataSet will be DataRowState.Unchanged and the update method will not be called.

By calling the EndCurrentEdit() method of the BindingContext if you have made changes to the give DataSet the DataRowState property will be set to DataRowState.Modified, this will then call the update method.

e.g. before you call the update method do this:

BindingContext(DataSetName, "DataTableName").EndCurrentEdit

Good Luck,
Gazzo
 
Back
Top