Hello all
I am writing a solicitor allocation application that will be used by multiple users at one time.
Because of this, the database needs to be updated with every change.
This is my code when a solicitor is chosen for allocation:

private void FindSolicitor(int type, bool stype)
        {
            table = "";
            row = 0;

            int t = 0;
            bool f = false;
            string s = "";

            char ctype = char.Parse(type.ToString());

            if (!stype)
            {
                t = 0;
                for (int i = 0; i < sadset.Tables["Solic"].Rows.Count; i++)
                {
                    if (sadset.Tables["Solic"].Rows[i]["State"].ToString() == "0" && ((sadset.Tables["Solic"].Rows[i]["Types"].ToString()).Contains(ctype)))
                    {
                        f = true;
                        sadset.Tables["Solic"].Rows[i]["State"] = 1;
 >>                     adsol.Update(sadset.Tables["Solic"]);

                        s = (string)sadset.Tables["Solic"].Rows[i]["Solicitor"];

                        table = "Solic";
                        row = i;
                        break;
                    }
                }
            }
            else
            {
                switch (exn)
                {
                    case (5):
                        t = 1;
                        for (int i = 0; i < sadset.Tables["Solicminor"].Rows.Count; i++)
                        {
                            if ((int)sadset.Tables["Solicminor"].Rows[i]["State"] == 0)
                            {
                                f = true;
                                sadset.Tables["Solicminor"].Rows[i]["State"] = 1;
 >>                             admin.Update(sadset.Tables["Solicminor"]);

                                s = (string)sadset.Tables["Solicminor"].Rows[i]["Solicitor"];

                                table = "Solicminor";
                                row = i;
                                break;
                            }
                        }
                        break;

                    case (6): // LQU goes to Bakers
                        t = 2;
                            if ((int)sadset.Tables["Solic"].Rows[1]["State"] == 0)
                            {
                                f = true;
                                sadset.Tables["Solic"].Rows[1]["State"] = 1;
 >>                             adsol.Update(sadset.Tables["Solic"]);

                                s = (string)sadset.Tables["Solic"].Rows[1]["Solicitor"];

                                table = "Solic";
                                row = 1;
                                break;
                            }
                        break;
                }
            }

            if (!f)
                Reset(t);
            else
            {
                active = true;
                lbsol.Text = s;
                p.Visible = true;
            }
        }

Every single time one of the Update commands is executed, DBConcurrency Exception is thrown. There is no declared update command; i have had no trouble in the past just using the autogenerated command.

Thanks in advance for any help

Dani AI

Generated

Nice catch, — a premature call to AcceptChanges is a common root cause for DBConcurrencyException. Briefly: the adapter’s generated UPDATE/DELETE usually uses a row’s Original values in the WHERE clause to detect concurrent modifications. Calling AcceptChanges too early resets Original/RowState and interferes with that matching logic (or removes the change tracking you rely on), so the UPDATE can affect zero rows and the adapter throws DBConcurrencyException.

Practical guidance and fixes:

  • Don’t call AcceptChanges before you call the DataAdapter/TableAdapter Update. By default Update will mark rows as accepted for you after a successful database operation.
  • If you need precise control, set AcceptChangesDuringUpdate = false on the adapter, call Update(...), then call AcceptChanges() yourself only after the update completes successfully. Example:
adapter.AcceptChangesDuringUpdate = false;
try {
  adapter.Update(ds, "Solic");
  ds.AcceptChanges(); // only now
} catch (DBConcurrencyException ex) {
  // reload the affected rows, resolve conflicts, or inform the user
}
  • For robust multi-user behavior, prefer a SQL Server rowversion (timestamp) column or an explicit optimistic-concurrency strategy rather than relying on comparing every column. That makes WHERE clauses reliable and conflicts easier to detect.
  • When a DBConcurrencyException happens, catch it, refresh the offending row(s) from the database (or call RejectChanges() and re-fetch), then merge/ retry or present a conflict resolution to the user.

These patterns avoid the invisible state-mismatches that AcceptChanges can introduce and make multi-user updates predictable and recoverable.

SORTED IT!

This was caused by a dataset.AcceptChanged(); before the initial code.

Sorry for being an idiot guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.