Hello,
I am writing a C# application that manipulates data in an Access database.
I have am using the OleDbDataAdapter to fill a DataSet with the records from
the database, whenever I attempt to update the same record during a session
a DBConcurrencyException is thrown.
I have read posts on the Internet that state that the problem is solved by
writing your own update statement, I did that and it still does not work.
Below, I have code posted for creating the Adapter and how the update
occurs.
Thanks in advance,
Will
// Creating the adapter
private static string strAddressSelect = "SELECT * FROM Address";
private static string strAddressUpdate = "UPDATE Address SET Address1 =
@address1, Address2 = @address2, City = @city, State = @state, Zip = @zip
WHERE ID = @theID";
OleDbConnection conn = App.GetConnection();
OleDbCommand cmd = conn.CreateCommand();
OleDbCommand updatecmd = null;
OleDbParameter idParm = new OleDbParameter("@theID", OleDbType.BigInt);
idParm.SourceColumn = "ID";
idParm.SourceVersion = DataRowVersion.Original;
if(tablename.CompareTo("Address") == 0)
{
cmd.CommandText = strAddressSelect;
addressAdapter = new OleDbDataAdapter(cmd);
addressBuilder = new OleDbCommandBuilder(addressAdapter);
addressAdapter.RowUpdated += new
OleDbRowUpdatedEventHandler(Adapter_OnRowUpdate);
updatecmd = new OleDbCommand(strAddressUpdate, conn);
updatecmd.Parameters.Add("@address1", OleDbType.VarChar, 50, "Address1");
updatecmd.Parameters.Add("@address2", OleDbType.VarChar, 50, "Address2");
updatecmd.Parameters.Add("@city", OleDbType.VarChar, 50, "City");
updatecmd.Parameters.Add("@state", OleDbType.VarChar, 50, "State");
updatecmd.Parameters.Add("@zip", OleDbType.VarChar, 50, "Zip");
updatecmd.Parameters.Add(idParm);
addressAdapter.UpdateCommand = updatecmd;
addressAdapter.Fill(ds, "Address");
}
// I'll make some changes
DataRow addressRow = GetAddressRow();
addressRow.BeginEdit();
addressRow["Address1"] = address1TB.Text;
addressRow["Address2"] = address2TB.Text;
addressRow["City"] = cityTB.Text;
addressRow["State"] = stateCB.Text;
addressRow["Zip"] = zipTB.Text;
addressRow.EndEdit();
addressAdapter.Update(ds, "Address");
// Exception gets thrown. I don't know what else to do and I have been at
this for some weeks.
--
__________________________________________________ ___
Today's science fiction is tomorrow's science reality.
Never question the eccentricity of man or the plausibility
of the human spirit.
- William Lee Mapp, III, Dreamer
William Lee Mapp, III
Co-Founder
Managing Officer, BA Systems, LLC
mapp (AT) basystemsllc (DOT) com
http://www.basystemsllc.com
Less Theory, More Reality