Retrieve Identity value from inserted row in Access Database using TableAdapter

Following on from...

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=58862

I would like to retrieve the value of an inserted identity column from an Access database immediately after a new row is inserted using C#.

The example in the post above uses VB andI am confused about where to put the following statement:


m_adapter.RowUpdated +=newOleDbRowUpdatedEventHandler(m_adapter_RowUpdated);

m_adapter refers to the TableAdapters OleDbDataAdapter in the designer.cs file. The only places I can think to put it are the TableAdapter constructor and the TableAdapter InitAdapter() method. Both of these reside in the designer.cs file and would be overwritten if I changed the DataSet.How can I hook into the RowUpdated event using C# in a partial class outside of the mydataset.designer.cs file?

I may of course be missing the point! Many thanks for your help.

[1412 byte] By [BenS] at [2007-12-16]
# 1
I did it by adding a public property to the MyTableAdapter class that exposes MyTableAdapter's Adapter property (which is an OleDbDataAdapter). I could then add the RowUpdated event handler from anywhere within my code.
It works, but doesn't seem like an ideal solution.
BenS at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
Ben,

That's as ideal a solution as you're going to find. The scenario is easier to handle in VB.NET because of the Handles keyword.

DavidSceppa at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3
Ben, how did you do that? (newbie)

Can this be done if I'm using table adapters that are generated with Dataset Wizard?

I allready changed the baseclass of my tableadapter to MyNamespace.MytableAdapter.
On a different cs file, i created a public partial class of MyTableAdapter, which inherets from System.ComponentModel.Component.

I'm still missing the important part though. I set the Apapter property, but how can I expose the adapter? Will it perform better if I expose the transaction and then try to work with it?

Thanks in advance.

Daniel Sovino

danielsovino at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified