Concurrency violation - concurrency_error_watch.xls (0/1)

  • Thread starter Thread starter nick
  • Start date Start date
N

nick

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 with no
problem. Here's the code that's causing the problem:

public void UpdateDataSource(Dancers.allbookings ChangedRows)
{
try
{
if ((ChangedRows != null))
{
this.oleDbConnection1.Open();
oleDbDataAdapter1.Update(ChangedRows);
}
}
catch (System.Exception updateException)
{
throw updateException;
}
finally
{
this.oleDbConnection1.Close();
}

}

An error occurs trying to execute the line:

oleDbDataAdapter1.Update(ChangedRows);

I found nothing wrong when trying to track from the watch list the
data from the row to be updated, as below (can be viewed a lot clearer
from the attached excel file):

- ChangedRows.tbprivate[0]
{Dancers.allbookings.tbprivateRow}
Dancers.allbookings.tbprivateRow
+ System.Data.DataRow {Dancers.allbookings.tbprivateRow}
System.Data.DataRow
cancelled FALSE bool
dancerid 6 int
finished TRUE bool
len 20 byte
pclub 30 short
pdancer 55 short
privateid 65 int
room A string
+ shift {8/2/2004} System.DateTime
start 20:20 string
+ tabletbprivate {Dancers.allbookings.tbprivateDataTable}
Dancers.allbookings.tbprivateDataTable
ChangedRows.Tables["tbprivate"].Rows[0].RowError
Concurrency violation: the UpdateCommand affected 0 records. string
 
Hi Nick,

When you do it this way,
oleDbDataAdapter1.Update(ChangedRows);

I asume that ChangedRows is the dataset.ChangedRows than the acceptchanges
is not done automaticly by the oleDbDataAdapter, the next time you do than
an update you get a concurrency errror.

Can it be that?

Cor
 
Hi Nick,

When you do it this way,

I asume that ChangedRows is the dataset.ChangedRows than the acceptchanges
is not done automaticly by the oleDbDataAdapter, the next time you do than
an update you get a concurrency errror.

Can it be that?

Cor

OK here's the code sequece: When the update button is pressed,
"UpdateDataSet" is called:

public void UpdateDataSet()
{
Dancers.allbookings objDataSetChanges = new
Dancers.allbookings();

this.BindingContext[objallbookings,"tbprivate"].EndCurrentEdit();
objDataSetChanges =
((Dancers.allbookings)(objallbookings.GetChanges()));

// Check to see if any changes have been made.
if ((objDataSetChanges != null))
{
try
{
this.UpdateDataSource(objDataSetChanges);
objallbookings.Merge(objDataSetChanges);
objallbookings.AcceptChanges();
}
catch (System.Exception eUpdate)
{
throw eUpdate;
}
}
}

which then calls "UpdateDataSource" from:

this.UpdateDataSource(objDataSetChanges);

"objDataSetChanges" is passed in as "ChangedRows" to
"UpdateDataSource". As mentioned before, it breaks down when executing
"oleDbDataAdapter1.Update(ChangedRows)" within "UpdateDataSource". I
suspect there's some data inconsistency but by looking at the
"ChangeRows" (which only have 1 row in this case) it all seems fine.
 
Hello Nick,

Thanks for your post. As I understand, the problem you are facing is that
it throws DBConcurrencyException when calling DbDataAdapter.Update method.
By default, the Update method ends and raises a DBConcurrencyException
exception when the method encounters a row that fails to update. I think
more information is needed before moving forward:

1. What's the database, SQL Server, Microsoft Access, etc?

2. In the DataRow, does it contain the "System.Data.OleDb.OleDbType.DBDate"
type for mapping DateTime data? If so, based on my experience, there is a
known issue to cause such error and we need to use
System.DataOleDb.OleDbType.Date instead of
System.Data.OleDb.OleDbType.DBDate.

3. If the problem persists, is it possible for you to post a sample project
and database which is able to reproduce the problem? I will be glad to
check it on my side.

I look forward to hearing from you.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hello Nick,

Thanks for your post. As I understand, the problem you are facing is that
it throws DBConcurrencyException when calling DbDataAdapter.Update method.
By default, the Update method ends and raises a DBConcurrencyException
exception when the method encounters a row that fails to update. I think
more information is needed before moving forward:

1. What's the database, SQL Server, Microsoft Access, etc?

It's MSAccess.
2. In the DataRow, does it contain the "System.Data.OleDb.OleDbType.DBDate"
type for mapping DateTime data? If so, based on my experience, there is a
known issue to cause such error and we need to use
System.DataOleDb.OleDbType.Date instead of
System.Data.OleDb.OleDbType.DBDate.

Here's the code to create the updatecommand for oleDbDataAdapter1:

updatesql = "UPDATE tbprivate SET dancerid = @dancerid, len = @len,
start = @start, pdancer = @pdancer, pclub = @pclub, room = @room,
finished = @finished, cancelled = @cancelled, shift = #" + GetShift()
+ "# WHERE privateid = @privateid";

where GetShift() will return a date like "2/8/2004".

oleDbDataAdapter1.UpdateCommand = new
OleDbCommand(updatesql,oleDbConnection1);
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@privateid",
OleDbType.BigInt,4, "privateid");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@dancerid",
OleDbType.BigInt,4, "dancerid");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@len",
OleDbType.TinyInt,1, "len");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@room",
OleDbType.VarChar,1, "room");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@start",
OleDbType.VarChar,5, "start");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@pclub",
OleDbType.TinyInt,4, "pclub");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@pdancer",
OleDbType.TinyInt,4, "pdancer");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@finished",
OleDbType.Boolean,1, "finished");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@cancelled",
OleDbType.Boolean,1, "cancelled");
oleDbDataAdapter1.UpdateCommand.Parameters.Add("@shift",
OleDbType.Date,0, "shift");
 
Hi Nick,

What is the reason you do this,
this.UpdateDataSource(objDataSetChanges);
objallbookings.Merge(objDataSetChanges);
objallbookings.AcceptChanges();

If I see it good you try to merge to the dataset a set of rows which are
already completly in this dataset if the program works correct than that
should give an concurrency error..

I think it is better to do an update of the whole dataset. (I have done it a
while a little bit the same as you although without the merge, I am not
secure if all checkings are done correct with this method).

You do than also not need that acceptchanges, because the dataadapter does
it for you if everything went correct.

Cor
 
Hi Nick,

What is the reason you do this,

objallbookings is the existing dataset. UpdateDataSource updates the
underlying datasource (actually updating the database). The last 2
lines commits changes to the dataset. How else would you do it??
If I see it good you try to merge to the dataset a set of rows which are
already completly in this dataset if the program works correct than that
should give an concurrency error..

See above.
I think it is better to do an update of the whole dataset. (I have done it a
while a little bit the same as you although without the merge, I am not
secure if all checkings are done correct with this method).

I have been doing it this way ALL the time, only this particular grid
fails me. I am suspecting it's the data in the row(s) that's giving
the underlying database inconsistent update, but I can't figure out
which column, cause as you can see from the watch (excel file) all
data seems pretty normal.

Anyone?
 
Hi Nick,

I would first try what I did advice when than the concurrency error is not
gonne than it is something else.

:-)

Cor
 
Hi Nick,

I would first try what I did advice when than the concurrency error is not
gonne than it is something else.

:-)

Cor

Umm.. I don't quite understand what you're suggesting. Perhaps some
code might help?
 
To test
this.UpdateDataSource(objallbookings);
// objallbookings.Merge(objDataSetChanges);
// objallbookings.AcceptChanges();
 
To test
this.UpdateDataSource(objallbookings);
// objallbookings.Merge(objDataSetChanges);
// objallbookings.AcceptChanges();

Umm I thought it was pretty clear I mentioned it's "UpdateDataSource"
that's causing the problem?
 
Hi Nick,

Thanks for your response. I reviewed your code snippet carefully, I noticed
that "shift" value is directly got from GetShft so that we should not add
@shift parameter to the UndateCommand. Please remove it and then check
whether or not the problem still exists.

I am standing by for your result.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Nick,

Thanks for your response. I reviewed your code snippet carefully, I noticed
that "shift" value is directly got from GetShft so that we should not add
@shift parameter to the UndateCommand. Please remove it and then check
whether or not the problem still exists.

I am standing by for your result.

Exactly the same error.
 
Hi Nick,

Since the problem persists, could you please post a sample project with
MDB file and tell me the detailed steps to reproduce the problem? That
will be most helpful for me to pinpoint the problem and resolution.

I am standing by for your response.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Nick,

Since the problem persists, could you please post a sample project with
MDB file and tell me the detailed steps to reproduce the problem? That
will be most helpful for me to pinpoint the problem and resolution.

Do I just email the project (slimmed down version) to you? It's about
1.5mb compressed, including the Access db.
 
Hello Nick,

You can ZIP the files and email it to me directly. Thanks.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Nick,

Thanks for your project. I received it and am now performing research on
it. I will update you with my information.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Nick,

Thanks for your project. I received it and am now performing research on
it. I will update you with my information.

Thanks for your help. Waiting for the good news :)
 
Back
Top