问题
I'm VB .net 2010 with a MS Access 2010 Database.
The wizard created a DataSet with all the tables from the database. So, I can use
Me.CostumerAdapter.Insert("New Costumer")
And that works flawless.
But then I've a grid with some Products (Just the Name)
Product #1
Product #2
Product #3
...
When I save the new costumer I need to get its ID so I can insert the products list. Product & Costumer already have a foreing key relationship.
How can I get the Costumer inserted ID? Or how can I save all together?
All I found was for SQL Server (@@IDENTITY, SCOPE_IDENTITY).
I tried adding a new INSERT Statement on the datatable (dataset):
INSERT INTO Costumer VALUES (?);
SELECT @@IDENTITY;
Set the query to Scalar and that gave me an error. ('Characters were found after query')
Thanks! Sorry for any grammatical error.
回答1:
Have to use OleDB Commands:
http://www.mikesdotnetting.com/Article/54/Getting-the-identity-of-the-most-recently-added-record
来源:https://stackoverflow.com/questions/12874526/ms-access-tableadapter-get-identity-after-insert