Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

Going MAD when trying to delete from datatable.

Apr 4 2003 1:37 AM
I've tried everything - except the working solution of course. I want to delete some or all rows from a datatable and the update that back to the access database before adding new rows (BTW, adding works fine). I have used foreach () to do row.delete() and also tried datatable.clear(). They both seem to work fine, but the problem arises when I want to update the database through the oleDBdataadapter. int res=oleDbAdaptMatchings.Update(dtMatchings); //Save to database The above line either does nothing in the database or whines about the auto-generated insert/delete/update commands. Yes, I am using the CommandBuilder. The table in question has no PK. Is that really necessary for such a simple procedure? I have tried setting my own PK for the table to avoid the dataadapter whining: DataColumn[] priKeys=new DataColumn[3]; priKeys[0] = dtMatchings.Columns["systemID"]; priKeys[1] = dtMatchings.Columns["nyckellista"]; priKeys[2] = dtMatchings.Columns["cylinderlista"]; dtMatchings.PrimaryKey = priKeys; The adapter couln't care less. So, What code lines are needed for something like this? I have read examples in at least 15 places on the web but nothing works. What is the difference between ...update(datatable) and ...update(dataset)? ARRGH! Please help ! Exactly what lines of code do I need? And why? /Björn

Answers (6)