Error updating AutoNumber field in MS Access

S

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
 
C

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top