Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataRowCollection.Clear

Status
Not open for further replies.

notgumbel

Programmer
Nov 23, 2007
3
US
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.


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.
 
The DataRowCollection.Clear() is only clearing the items from that instance of the DataRowCollection, it's not actually deleting the records from your database so all that data should still be in the table when you go to update it from the XML file.

-jhaith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top