G
Guest
Hello,
I am working on a C# application that uses an Access 2003 database. The
database is also the back end for a much larger (and much older) VB6 project.
The primary key to each table is an ID field that is built from two fields,
CounterID and StoreID. CounterID is an auto number field, and StoreID is a
configurable number that is incremented manually every time a compact and
repair is performed on the database.
I can not figure out how to build the ID field in ADO.NET. I have tried
using the data adapters OnRowUpdate event, but my ID field is 0 in the
database. Here is an example of what I've tried:
static void oDataAdapter_OnRowUpdate(object sender,
OleDbRowUpdatedEventArgs e)
{
OleDbCommand oCmd = new OleDbCommand("SELECT @@IDENTITY",
e.Command.Connection);
e.Row["COUNTERID"] = oCmd.ExecuteScalar();
//Temp
e.Row["STOREID"] = 1;
string temp = "0";
e.Row["ID"] = e.Row["COUNTERID"].ToString() +
e.Row["STOREID"].ToString().PadLeft(2, temp[0]);
e.Row.AcceptChanges();
}
What am I doing wrong?
Regards,
David
I am working on a C# application that uses an Access 2003 database. The
database is also the back end for a much larger (and much older) VB6 project.
The primary key to each table is an ID field that is built from two fields,
CounterID and StoreID. CounterID is an auto number field, and StoreID is a
configurable number that is incremented manually every time a compact and
repair is performed on the database.
I can not figure out how to build the ID field in ADO.NET. I have tried
using the data adapters OnRowUpdate event, but my ID field is 0 in the
database. Here is an example of what I've tried:
static void oDataAdapter_OnRowUpdate(object sender,
OleDbRowUpdatedEventArgs e)
{
OleDbCommand oCmd = new OleDbCommand("SELECT @@IDENTITY",
e.Command.Connection);
e.Row["COUNTERID"] = oCmd.ExecuteScalar();
//Temp
e.Row["STOREID"] = 1;
string temp = "0";
e.Row["ID"] = e.Row["COUNTERID"].ToString() +
e.Row["STOREID"].ToString().PadLeft(2, temp[0]);
e.Row.AcceptChanges();
}
What am I doing wrong?
Regards,
David