Home All Groups Group Topic Archive Search About

Error updating AutoNumber field in MS Access

Author
10 Feb 2006 3:06 AM
sek
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

Author
10 Feb 2006 6:45 AM
Cor Ligthert [MVP]
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

AddThis Social Bookmark Button