Delete Record Question

  • Thread starter Thread starter Tina
  • Start date Start date
T

Tina

I have a SQLDataAdapter created with the wizard and having all of the
commands including the DeleteCommand - I used the defaults.

To delete a record, this works just fine:
myDA.SelectCommand.Parameters("@mykey").Value = mykey
myDS.Clear()
myDA.Fill(myDS)
If myDS.mytable.Rows.Count > 0 Then
myDS.mytable.Rows.Item(0).Delete()
myDA.Update(myDS)
End If

However, it seems that I should be able to do this in a more straightforward
manner using the DeleteCommand. How should this be done with a minimum of
code?
thanks,
T
 
Just call myTable.Rows.Item(Whatever).Delete

I can't really tell what this is supposed to do, but if you just want to
delete a record, fill in Whatever with the index and it'll delete the
record. When you call Update, the adapter will check all of the rows with a
rowstate or Deleted and issue the delete command against that record, one by
one for each row who's rowstate has been changed (deleted in this case).

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
 
Back
Top