I have a database that I recieve replacement updates on via text file. I need to be able to delete every row/record within a table. I've tried to execute a command object like so:
''''''''''''''''''''''''''''''''''''''''''''''''
'delete the records
Dim cn As New OleDb.OleDbConnection()
'cnautocar.connectionstring being another connectionstring
'that I know works. cnAutoCar is actually the connection
'that I used obtain the datatable by adding a connection
'in server explorer
cn.ConnectionString = cnAutoCar.ConnectionString
cn.Open()
myCommand.ExecuteNonQuery()
cn.Close()
cn = Nothing
'''''''''''''''''''''''''''''''''''''''''''''''''
I have also tried looping through the table deleting each row and then updating before I begin the addition data.
'''''''''''''''''''''''''''''''''''''''''''''''''
Dim myRow As DataRow
Dim Counter As Integer
For Each myRow In DsImperialMstr1.Imperialvdmstr.Rows
myRow.Delete()
Next
daImperialVDMstr.Update(DsImperialMstr1)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
All I do after that is create row, edit fields within it, add the row to the table, and then I call update like this:
''''''''''''''''''''''''''''''''''''''''''''''''''''''
daImperialVDMstr.Update(DsImperialMstr1)
When I use the command object to delete the records I recieve a message that "ExecuteNonQuery: Connection has not been initialized" Error number 5.
When I loop through the records I recieve the error that I am creating duplicate records because the original records are not being deleted.
If you see something I've missed in either method of deleting all rows from the table within the database please let me know.
I'm not picky about how I do it. I just need to be able to empty all the records before I replace them.
Thanks
''''''''''''''''''''''''''''''''''''''''''''''''
'delete the records
Dim cn As New OleDb.OleDbConnection()
'cnautocar.connectionstring being another connectionstring
'that I know works. cnAutoCar is actually the connection
'that I used obtain the datatable by adding a connection
'in server explorer
cn.ConnectionString = cnAutoCar.ConnectionString
cn.Open()
myCommand.ExecuteNonQuery()
cn.Close()
cn = Nothing
'''''''''''''''''''''''''''''''''''''''''''''''''
I have also tried looping through the table deleting each row and then updating before I begin the addition data.
'''''''''''''''''''''''''''''''''''''''''''''''''
Dim myRow As DataRow
Dim Counter As Integer
For Each myRow In DsImperialMstr1.Imperialvdmstr.Rows
myRow.Delete()
Next
daImperialVDMstr.Update(DsImperialMstr1)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
All I do after that is create row, edit fields within it, add the row to the table, and then I call update like this:
''''''''''''''''''''''''''''''''''''''''''''''''''''''
daImperialVDMstr.Update(DsImperialMstr1)
When I use the command object to delete the records I recieve a message that "ExecuteNonQuery: Connection has not been initialized" Error number 5.
When I loop through the records I recieve the error that I am creating duplicate records because the original records are not being deleted.
If you see something I've missed in either method of deleting all rows from the table within the database please let me know.
I'm not picky about how I do it. I just need to be able to empty all the records before I replace them.
Thanks