HighTechTalks DotNet Forums  

OleDbDataAdapter throws DBConcurrencyException on update

Dotnet Framework (ODBC.net) microsoft.public.dotnet.framework.odbcnet


Discuss OleDbDataAdapter throws DBConcurrencyException on update in the Dotnet Framework (ODBC.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
William Lee Mapp III
 
Posts: n/a

Default OleDbDataAdapter throws DBConcurrencyException on update - 12-06-2003 , 05:34 PM






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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.