MS Access TableAdapter Get Identity after insert

只谈情不闲聊 提交于 2020-01-06 17:45:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!