PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Error updating AutoNumber field in MS Access

Reply

Error updating AutoNumber field in MS Access

 
Thread Tools Rate Thread
Old 10-02-2006, 03:06 AM   #1
sek
Guest
 
Posts: n/a
Default Error updating AutoNumber field in MS Access


Hi Folks,

I am using Access and OleDb in ADO.NET in my application. Basically, my
app allows users to view the db and add new rows to it using DataGrid
control.

My unique field in the table is a AutoNumber field.

When i try to add a new row through the datagrid and then invoke
DataAdapter.Update method, following exception is thrown.

"Index (zero based) must be greater than or equal to zero and less than
the size of the argument list."

Following is the stack trace:

at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at MyProj.ClassDb.UpdateTable(DataSet dsRecords) in e:\code\c#\....

Moreover, I am using the RowUpdated event handler to get the AutoNumber
value generated for the new row. In the event handler, i am getting the
RowUpdatedEventArgs.Status = "ErrorsOccured".

Any pointers would be of great help.

TIA.
Sek

  Reply With Quote
Old 10-02-2006, 06:45 AM   #2
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: Error updating AutoNumber field in MS Access

Sek,

For OleDB Access, you cannot update the really created AutoNumber.

Therefore you have to do something as this.

myDataAdapger.update(whatever)
Whatever.clear
myDataAdapter.fill(whatever)

A better choose for an autonumber is a GUID (UniqueIdentifier) by the way,
than you don't need that consequently filling.

I hope this helps,

Cor


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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