Batch updates on generated TableAdapters throws InvalidOperation

  • Thread starter Thread starter Some Bloke
  • Start date Start date
S

Some Bloke

Hi,

I'm trying to write a data layer for to persist regularly occuring
stats to a database using ADO.NET by collecting a few records then
updating the database in batches.

I've got a Dataset that is generated with MSDataSetGenerator that I
add rows to then pass to the Update method of the generated
TableAdapter.

When I set the batch size to anything more than 1, I get "When
batching, the command's UpdatedRowSource property value of
UpdateRowSource.FirstReturnedRecord or UpdateRowSource.Both is
invalid"

Doing a search for that exception returns no results, hence me asking
for help, but looking into it I see that UpdateRowSource.Both is the
default value but the generated InitAdapter() method of the
TableAdpater that creates the update/insert commands doesn't override
this, leading to the exception.

Strangely this did appear to be working at one point but I can not
figure out what has changed.

How can I get the code generator to set the UpdateRowSource to None?
Or is there something that I could have missed that would cause this?
Possibly a change to the database?

Thanks for any help.
 
I'm still having problems with this. Right now I've added the line
this._adapter.InsertCommand.UpdatedRowSource =
System.Data.UpdateRowSource.None;
to the InitAdapter() method in the generated TableAdapter.

This means I have to be careful to replace it after making changes. I
can't think how to do this in the partial class.

Do Visual Studio's TableAdapters really offer no support for Batch
Updates???
 
I'm still having problems with this. Right now I've added the line
            this._adapter.InsertCommand.UpdatedRowSource =
System.Data.UpdateRowSource.None;
to the InitAdapter() method in the generated TableAdapter.

This means I have to be careful to replace it after making changes. I
can't think how to do this in the partial class.

Do Visual Studio's TableAdapters really offer no support for Batch
Updates???

OK. I've added a property to the partial class. It does mean I have to
set it explicitly before doing an update but it will do the job.

public bool Batching
{
set
{
if (value)
{
_adapter.InsertCommand.UpdatedRowSource =
System.Data.UpdateRowSource.None;
_adapter.UpdateCommand.UpdatedRowSource =
System.Data.UpdateRowSource.None;
}
}
}

Hope this is useful to somebody.
 
Back
Top