how to build & set a custom update command

  • Thread starter Thread starter Neo
  • Start date Start date
N

Neo

I konw that one can make use of the default UpdateCommand in the DataAdapter
to save changes back into the underlying data source.
But i was wondering how one could build a custom update command & set this
into the DataAdapter & when the Update method of the Data Adapter is issued,
then this update command should be used.

Esp, if the table is Customer with the following fields,
ID = Primary Key Field (Integer)
Name = Varchar
Male = Bit

UpdateCmd = "UPDATE Contacts SET Name=@Name, Male=@Male WHERE ID=@ID"
But to do this, i need to add the parameters into the update command of the
format,

UpDataCmd.Parameters.Add("@Name", <Column Data Type>, <Column Size>, "Name")
UpDataCmd.Parameters.Add("@Male", <Column Data Type>, <Column Size>, "Male")
UpDataCmd.Parameters.Add("@ID", <Column Data Type>, <Column Size>, "ID")

Now, is there a way i could determine the above,
the Data Type of the columns (SQL Data type) & the Size of the fields (in
the SQL Table).
I don't mind querying the data base to get this info).

Thanx,

Neo
 
Basically what i need is a way of determining the SQL Data type of a column
& the Size of a column.
I found one way of doing this, but may not be the best (then again, this is
what i could comeup with),

I make use of the SQLCommandBuilder class to build the Update command,
& using this generated Update Command, i loop through the Parameters
collection,
& from there i determin the SQLDataType & the size of the field (from the
Parameter object attributes).

Neo
 
Back
Top