building an update statement at runtime

  • Thread starter Thread starter col
  • Start date Start date
C

col

At runtime the SqlDataAdapter is used to populate a recordset from one of
many possible tables. As a result the update command must also be build at
runtime. CommandBuilder is not an option as it does not support spaces in
column names.

How do I go about building an update statement?

Thanks,
Colin.
 
Just set the CommandObject properties. You can declare the command wherever
you want, and set all of the update logic (or ideally name the stored procs)
wherever you want.
 
col said:
At runtime the SqlDataAdapter is used to populate a recordset from one of
many possible tables. As a result the update command must also be build at
runtime. CommandBuilder is not an option as it does not support spaces in
column names.

CommandBuilder will work fine.

Dim cb As SqlCommandBuilder
.. . .
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"

And next time follow the rules with naming columns.

David
 
William,

I wish to build the actual update command on the fly, what is the syntax as
far as specifying SET and WHERE?
 
It's standard syntax Update mytable Set Column1 = 'x' Where somevaule =
'z'. You can escape the spaced fields by enclosing them with [ and ] but
I'd recommend that you get rid of the columns with spaces in them...more
trouble then they are worth.

HTH,

Bill
 
Back
Top