How do I hook to an insert in a typed dataset

  • Thread starter Thread starter Ken Foskey
  • Start date Start date
K

Ken Foskey

I need to trap an insert on an MS access table that uses a generated
typed table and row setup. I have to trap the insert and then hook up
and get the autonumber value for the insert. I have googled this and
cannot find a typed solution to the problem. I either abandon type
safety or solve this problem.

I have to work around 'Refresh the data table' that is greyed out.

Ta
Ken
 
I need to trap an insert on an MS access table that uses a generated
typed table and row setup. I have to trap the insert and then hook up
and get the autonumber value for the insert. I have googled this and
cannot find a typed solution to the problem. I either abandon type
safety or solve this problem.

I have to work around 'Refresh the data table' that is greyed out.

MyDataset is from the xsd designed Dummy is your table name. You will
add the TableAdapter to your application from the toolbox. I cannot find
this easily documented anywhere.

I finally figured this out. In my initialise:

DummyTableAdapter.Adapter.RowUpdated += InsertDummy;

Then created the event:

private void InsertDummy(object sender,
System.Data.OleDb.OleDbRowUpdatedEventArgs args)
{
if (args.StatementType == StatementType.Insert)
{
MyDataSet.DummyRow ball = (MyDataSet.DummyRow)args.Row;

// Include a variable and a command to retrieve the
identity value from the Access database.
int newID = 0;
OleDbCommand idCMD = new OleDbCommand("SELECT
@@IDENTITY", DummyAdapter.Connection);

// Retrieve the identity value and store it in the
CategoryID column.
newID = (int)idCMD.ExecuteScalar();
ball.ID = newID; // my autonumber primary key
}
}


Creative Commons.
 
MyDataset is from the xsd designed Dummy is your table name. You will
add the TableAdapter to your application from the toolbox. I cannot
find this easily documented anywhere.

I finally figured this out. In my initialise:

DummyTableAdapter.Adapter.RowUpdated += InsertDummy;

Then created the event:

private void InsertDummy(object sender,
System.Data.OleDb.OleDbRowUpdatedEventArgs args)
{
if (args.StatementType == StatementType.Insert) {
MyDataSet.DummyRow ball = (MyDataSet.DummyRow)args.Row;

// Include a variable and a command to retrieve the
identity value from the Access database.
int newID = 0;
OleDbCommand idCMD = new OleDbCommand("SELECT
@@IDENTITY", DummyAdapter.Connection);

// Retrieve the identity value and store it in the
CategoryID column.
newID = (int)idCMD.ExecuteScalar();
ball.ID = newID; // my autonumber primary key
}
}


Creative Commons.



And I am still getting concurrency violation. How do I solve this
problem.
 

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

Back
Top