Deleting record gives me dbconcurrency exception

  • Thread starter Thread starter Chris Thunell
  • Start date Start date
C

Chris Thunell

I am trying to delete all the records in a table, but I keep getting a
system.data.dbconcurrency exception. Is there an easy was to delete all the
records in a sql table?

Here is my code... i get the error on the dataadapter.update:

MessageBox.Show(Me.DataSet11.tblPreReqWorking.Rows.Count)
'get rid of any records in memory
Me.DataSet11.tblPreReqWorking.Clear()
Me.daPreReqWorking.SelectCommand.CommandText = "Select JobNo, ReqNo, SeqNo
From dbo.tblPreReqWorking"

Me.daPreReqWorking.Fill(Me.DataSet11.tblPreReqWorking)
MessageBox.Show(Me.DataSet11.tblPreReqWorking.Rows.Count)
Dim myRow As DataRow
For Each myRow In Me.DataSet11.tblPreReqWorking
myRow.Delete()
Next
'this is where i get the dbconcurrency error
Me.daPreReqWorking.Update(Me.DataSet11.tblPreReqWorking)
'i don't get this far
Me.DataSet11.tblPreReqWorking.Clear()
 
Hi Chris,

Based on my understanding, you got a System.Data.DBConcurrencyException
when updating the database from the DataSet.

From the document, we can see that System.Data.DBConcurrencyException is
thrown by the DataAdapter during the update operation if the number of rows
affected equals zero. First, is the row count equals to 0 after filling the
DataSet? However I think you might have got a non-zero number. After
reading your code, I think there might be something wrong with the
daPreReqWorking.DeleteCommand. Please try to check it, or run the this
command in some tool like Query Analyzer to see if it can affect any
records in the database.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Chris Thunell" <[email protected]>
| Subject: Deleting record gives me dbconcurrency exception
| Date: Wed, 12 Nov 2003 09:28:09 -0500
| Lines: 24
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.languages.v
b
| NNTP-Posting-Host: 24-249-184-208.dsl.lan2wan.com 208.184.249.24
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156147
microsoft.public.dotnet.framework.adonet:66121
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| I am trying to delete all the records in a table, but I keep getting a
| system.data.dbconcurrency exception. Is there an easy was to delete all
the
| records in a sql table?
|
| Here is my code... i get the error on the dataadapter.update:
|
| MessageBox.Show(Me.DataSet11.tblPreReqWorking.Rows.Count)
| 'get rid of any records in memory
| Me.DataSet11.tblPreReqWorking.Clear()
| Me.daPreReqWorking.SelectCommand.CommandText = "Select JobNo, ReqNo, SeqNo
| From dbo.tblPreReqWorking"
|
| Me.daPreReqWorking.Fill(Me.DataSet11.tblPreReqWorking)
| MessageBox.Show(Me.DataSet11.tblPreReqWorking.Rows.Count)
| Dim myRow As DataRow
| For Each myRow In Me.DataSet11.tblPreReqWorking
| myRow.Delete()
| Next
| 'this is where i get the dbconcurrency error
| Me.daPreReqWorking.Update(Me.DataSet11.tblPreReqWorking)
| 'i don't get this far
| Me.DataSet11.tblPreReqWorking.Clear()
|
|
|
 
It was something to do with the dataadapter not being setup correctly. I
created a new dataadapter with no parameters... and i was then able to
delete all the records in the table. My original datadapter had parameters
like JobNo = xxx which through off the update command i guess.

Thanks everyone for your help!
 
Back
Top