I have a table that gets populated from an XML file via a dataset. The table should be empty at the start of the routine, but just to be sure, I always try to delete any existing records.
It worked just fine when I used an OLEDB command (DELETE * FROM tblJobHeader). However, I read about DataRowCollection.Clear and wanted to try & incorporate that.
It worked just fine when I used an OLEDB command (DELETE * FROM tblJobHeader). However, I read about DataRowCollection.Clear and wanted to try & incorporate that.
Code:
Dim dataSet As DataSet = New DataSet
Using connection As New OleDbConnection(stbConnectionString.ToString)
Dim adapter As New OleDbDataAdapter()
adapter.SelectCommand = New OleDbCommand("SELECT * FROM tblJobHeader", connection)
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter)
connection.Open()
adapter.Fill(dataSet, "tblJobHeader")
' Row count is 1 at this point
Dim drc As DataRowCollection = dataSet.Tables("tblJobHeader").Rows
drc.Clear()
' Row count is 0 at this point
' Particular XML file contains one record, same data as previously existed in tblJobHeader
dataSet = DataSetFromXML(strJobHeader)
builder.GetUpdateCommand()
adapter.Update(dataSet, "tblJobHeader")
End Using
[/code ]
Error = duplicate key (which would happen if the existing row were not truly deleted)
Perhaps I should just stick with the OLEDB command for deletion?
Thanks in advance.