Using the DeleteCommand

Hi,

I have a problem deleting rows from a table when I'm done processing the data in VB. I'm able to do bulk inserts with no problem but cannot find out how to do the updates. I have spent HOURS searching MSDN and help with no luck. How do I set the values for the DeleteCommand then execute

I'm using VS 2005 and SQL Server 2005,

Here is my code so far

Try

myNewEntryCoilsAdapter = New SqlDataAdapter("select * from NewEntryCoilID_TrendCoils", myConnection)
myNewEntryCoilsDataSet = New DataSet()
myNewEntryCoilsDataSet.CaseSensitive = True
myNewEntryCoilsAdapter.Fill(myNewEntryCoilsDataSet, "NewEntryCoilID_TrendCoils")
myNewEntryCoilsAdapter.DeleteCommand = New SqlCommand("DELETE FROM NewEntryCoilID_TrendCoils WHERE EntryCoilID=@EntryCoilID;", myConnection)
myNewEntryCoilsAdapter.DeleteCommand.Parameters.Add("@EntryCoilID", SqlDbType.Int, 4, "EntryCoilID")
myNewEntryCoilsAdapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None

If myNewEntryCoilsDataSet.Tables("NewEntryCoilID_TrendCoils").Rows.Count < 1 Then
Debug.Print("exit")
Exit Sub
End If
Dim myDataRow As DataRow
For Each myDataRow In myNewEntryCoilsDataSet.Tables("NewEntryCoilID_TrendCoils").Rows
EntryCoilID = myDataRow("EntryCoilID")
EntryMatID = myDataRow("ENTRYMATID").ToString()

' I call sub to process data here

'After process I want to delete the row I processed HERE

'then commit

Next
Catch e As Exception
Debug.Print("error")
'error
End Try



Answer this question

Using the DeleteCommand

  • Using the DeleteCommand