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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to delete and then repopulate an access2000 table

Status
Not open for further replies.

jlkidd

Programmer
Feb 22, 2001
28
0
0
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top