Click here to Skip to main content
11,492,523 members (61,097 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
hi,

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) {
            mydbDataSet.tblCfg.Rows[i].Delete();
            d++;
        }
        rs = mydbDataSet.tblCfg.Rows[i].RowState;
 
        //this.tblCfgTableAdapter.Update(mydbDataSet.tblCfg);
    }
 
    if (d > 0) {
        this.tblCfgTableAdapter.Update(mydbDataSet.tblCfg);
    }
}

"tblCfgTableAdapter.Update" throws DBConcurrencyException :

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

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 1:13am
fheyn717

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 399
1 Maciej Los 266
2 KarstenK 210
3 CPallini 208
4 Sascha Lefèvre 195
0 Sergey Alexandrovich Kryukov 9,943
1 OriginalGriff 8,610
2 Sascha Lefèvre 3,609
3 Maciej Los 3,372
4 Richard Deeming 2,440


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 31 Aug 2012
Copyright © CodeProject, 1999-2015
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