Click here to Skip to main content
13,048,846 members (68,229 online)
Rate this:
Please Sign up or sign in to vote.
See more:

with the following method i want to delete rows from a database-table:

private void deleteDataSetRows(string id)
    DataRowState rs;
    string  s;
    int     d = 0;
    for (int i=0; i < mydbDataSet.tblCfg.Rows.Count; i++) {
        s = mydbDataSet.tblCfg.Rows[i][2].ToString();
        s = mydbDataSet.tblCfg.Rows[i][0].ToString();
        if (s.TrimEnd(new char[]{' '}) == id) {
        rs = mydbDataSet.tblCfg.Rows[i].RowState;
    if (d > 0) {

"tblCfgTableAdapter.Update" throws DBConcurrencyException :

An unhandled exception of type 'System.Data.DBConcurrencyException' occurred
Additional information: Concurrency violation: the UpdateCommand affected 0

a) i changed the "for"-loop to execute only once : no exception
b) i changed the "for"-loop to execute twice : exception
c) i put tblCfgTableAdapter.Update within the loop : no exception

however c) to me appears as bad solution since you i have to keep track of rows remaining to delete and always have to delete row[0] because the Update of course will remove the row from the dataset as well as from tblCfg.
(tblCfg does not have a Primary Key)

what must i do to avoid this exception ?
please don't post links. for three days i've been looking in the internet and most posts deal with explaining the DBConcurrencyException.

thanks in advance
Posted 31-Aug-12 0:13am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 31 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100