Click here to Skip to main content
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
fheyn702

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

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


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