473,408 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

DBConcurrencyException

2G
Hi,

I seem to have some problems updating my dataset, I always get a error that
no rows were updated...:

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

If anyone would have a look at it , I would appreciate it.
Al works fine for the insert and the update works in another dataaccessor so
I shouldn't be my OleDbHelper.

Thanks.

public class ReagentDataAccessor : DataAccessor{

public ReagentDataAccessor() {

ReagentDataset ds = this.GetReagents();

ds.Reagents[0].Name = "Blabla";

this.Update(ds);

}

public ReagentDataset GetReagents() {

ReagentDataset ds = new ReagentDataset();

string sql = "Select * from Reagents";

OleDbHelper.FillDataset(this.Connection, CommandType.Text,

sql, ds, new string[]{ "Reagents" });

return ds;

}

public void Update(ReagentDataset ds){

OleDbHelper.UpdateDataset(this.GetInsertCommand(),

this.GetDeleteCommand(),

this.GetUpdateCommand(),

ds,

"Reagents");

}

protected override OleDbCommand GetInsertCommand(){

string sql = "Insert into Reagents (SkillId, Name, NPCPrice,
StackSize, PlacesFound, BImg) values (@SkillId, @Name, @NPCPrice,
@StackSize, @PlacesFound, @BImg)";

OleDbCommand cmd = new OleDbCommand(sql, this.Connection);

cmd.Parameters.Add("@SkillId", OleDbType.Integer, 0, "SkillId");

cmd.Parameters.Add("@Name", OleDbType.VarChar, 255, "Name");

cmd.Parameters.Add("@NPCPrice", OleDbType.Double, 0, "NPCPrice");

cmd.Parameters.Add("@StackSize", OleDbType.Integer, 0, "StackSize");

cmd.Parameters.Add("@PlacesFound", OleDbType.WChar, 0,
"PlacesFound");

cmd.Parameters.Add("@BImg", OleDbType.VarChar, 255, "BImg");

return cmd;

}

protected override OleDbCommand GetUpdateCommand(){

string sql = "UPDATE Reagents SET SkillId=@SkillId, Name=@Name WHERE
Id=@Id";

OleDbCommand cmd = new OleDbCommand(sql, this.Connection);

cmd.Parameters.Add("@Id", OleDbType.Integer, 0, "Id");

cmd.Parameters.Add("@SkillId", OleDbType.Integer, 0, "SkillId");

cmd.Parameters.Add("@Name", OleDbType.VarChar, 255, "Name");

// string sql = "Update Reagents set SkillId=@skillid, Name=@name,
NPCPrice=@npcprice, StackSize=@stacksize, PlacesFound=@placesfound,
BImg=@bimg Where Id=@id";

// OleDbCommand cmd = new OleDbCommand(sql, this.Connection);

// cmd.Parameters.Add("@id", OleDbType.Integer, 0, "Id");

// cmd.Parameters.Add("@skillid", OleDbType.VarChar, 255,
"SkillId");

// cmd.Parameters.Add("@name", OleDbType.VarChar, 255, "Name");

// cmd.Parameters.Add("@npcprice", OleDbType.Double, 0, "NPCPrice");

// cmd.Parameters.Add("@stacksize", OleDbType.Integer, 0,
"StackSize");

// cmd.Parameters.Add("@placesfound", OleDbType.WChar, 0,
"PlacesFound");

// cmd.Parameters.Add("@bimg", OleDbType.VarChar, 255, "BImg");

return cmd;

}

protected override OleDbCommand GetDeleteCommand(){

string sql = "Delete from Reagents where Id=@Id";

OleDbCommand cmd = new OleDbCommand(sql, this.Connection);

cmd.Parameters.Add("@Id", OleDbType.Integer, 0, "Id");

return cmd;

}

}
Nov 16 '05 #1
2 2932
2G <2G@pandora.be> wrote:
I seem to have some problems updating my dataset, I always get a error that
no rows were updated...:

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

If anyone would have a look at it , I would appreciate it.
Al works fine for the insert and the update works in another dataaccessor so
I shouldn't be my OleDbHelper.


The problem is that you're using parameters as if the names meant
something - for the OleDb provider, they don't (when using
CommandType=Text). They're just positional parameters - which may be
made clearer if you just use ? instead of names. If you reorder your
parameters for the update statement to be the same order as *in* the
statement, it should work.

See OleDbCommand.Parameters for more information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
2G
Ok, I changed it to :

string sql = "UPDATE Reagents SET SkillId=?, Name=? WHERE Id=?";

OleDbCommand cmd = new OleDbCommand(sql, this.Connection);

cmd.Parameters.Add("@skillid", OleDbType.Integer, 0, "SkillId");

cmd.Parameters.Add("@name", OleDbType.VarChar, 255, "Name");

cmd.Parameters.Add("@id", OleDbType.Integer, 0, "Id");

and now it works, thanks Jon.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
2G <2G@pandora.be> wrote:
I seem to have some problems updating my dataset, I always get a error that no rows were updated...:

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

If anyone would have a look at it , I would appreciate it.
Al works fine for the insert and the update works in another dataaccessor so I shouldn't be my OleDbHelper.


The problem is that you're using parameters as if the names meant
something - for the OleDb provider, they don't (when using
CommandType=Text). They're just positional parameters - which may be
made clearer if you just use ? instead of names. If you reorder your
parameters for the update statement to be the same order as *in* the
statement, it should work.

See OleDbCommand.Parameters for more information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Billy Jacobs | last post by:
I have a client using IE with a .net web application who is getting a Concurrency Violation whenever she tries to update certain records in her database. The strange thing is that I can open up...
25
by: nick | last post by:
I'm having trouble updating from a datagrid. It's says "Concurrency violation: the UpdateCommand affected 0 records", though I can't see how it's related to "concurrency". I can insert and delete...
0
by: Henrik de Jong | last post by:
Hello, I'm using radeditor. When I set the html-property to the text wich has to be altered, it gives me an error when try to save the new values of the html-proterty. It occurs only when i'm...
6
by: JohnR | last post by:
I have a table with 1 row which is used to hold some application wide items (one item per field, hence I only need 1 row). I want to bind one of the fields to a textbox. After setting up the...
1
by: niju | last post by:
Hi all, I am using following code to update database; I am running two instances of the application and updating the same record. However, DBConcurrencyException doesn't fire. Is there something...
3
by: Cub71 | last post by:
I am using Microsift Visual C# 2005 Express Edition and SQL Server 2005 Express Edition. I have created a few tables in the IDE. When I run my program in debug run the...
1
by: John | last post by:
Hi What is the purpose of exception.GetType and what are the possible values returned by it? Can it for example tell me if the exception is of type DBConcurrencyException? Thanks Regards
0
by: John | last post by:
Hi I am handling DBConcurrencyException for an adapter manager using code below. My problem is how to merge table in error with its copy from underlying database. If I need the table's data...
0
by: rote | last post by:
I have a TableDapter built from an Oracle Table. When i test for Concurrency by opening 2 sessions and edit the 2 at once the intial record record i update shows up and not the last one until i...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.