DataAdapter UpdateCommand

  • Thread starter Thread starter Mark Matheney
  • Start date Start date
M

Mark Matheney

Please help. Simple question.

I want to update a row in an SQL table. (using VS2003)

There are 2 keys:
tts_tkey and tts_tskey

and 3 fields to modify:

tts_activeflag
tts_lastmoddate
tts_lastmodifiedby

SqlUpdateCommandTS.CommandText = "UPDATE TechnicianSchedule " & _
"SET tts_activeflag = @tts_activeflag, " & _
"tts_lastmoddate = @tts_lastmoddate, " & _
"tts_lastmodifiedby = @tts_lastmodifiedby " & _
"WHERE (tts_tkey = @tts_tkey) AND (tts_tskey = @tts_tskey); "

' update this record ...

SqlDataAdapterTS.UpdateCommand.Parameters("@tts_tkey").Value =
tstomarkinactive_tkey(ct)
SqlDataAdapterTS.UpdateCommand.Parameters("@tts_tskey").Value =
tstomarkinactive_tskey(ct)
SqlDataAdapterTS.UpdateCommand.Parameters("@tts_activeflag").Value = 0
SqlDataAdapterTS.UpdateCommand.Parameters("@tts_lastmoddate").Value =
Now()
SqlDataAdapterTS.UpdateCommand.Parameters("@tts_lastmodifiedby").Value
= s_tkey

Not sure what command to use, but neither of the following will update
the database:

SqlUpdateCommandTS.ExecuteNonQuery()
SqlDataAdapterTS.UpdateCommand = SqlUpdateCommandTS

Basically, my question is: what commands do I use when I want to loop
through an internal array, updating a SQL table? (using a DataAdapter)

Many thanks in advance.

Mark
 
You call Update on the dataadapter. It does the looping through, and uses
column mappings to set the parameter. If you use the
DatatAdapterConfiguration wizard, take a look at the code it generates. The
whole purpose of using it is so you don't have to loop through anything
manually. You can call update on a table or a row, array of rows, dataset
etc.
 
William Ryan eMVP said:
You call Update on the dataadapter. It does the looping through, and uses
column mappings to set the parameter. If you use the
DatatAdapterConfiguration wizard, take a look at the code it generates. The
whole purpose of using it is so you don't have to loop through anything
manually. You can call update on a table or a row, array of rows, dataset
etc.

Would you please be so kind as to post the necessary lines of code for
the "update on the dataadapter". (I've tried, but can't seem to get
the syntax/order correct)

Thanks.

Mark
 
Mark:

It's basically just DataAdapter.Update(dataset, "TableName")

On the second adapter, you can use the DataAdapter Configuration Wizard to
generate the logic.
 
Back
Top