Incorrect ID is returned after insert using TableAdapter

SMUsamaShah picture SMUsamaShah · Jan 23, 2011 · Viewed 9.3k times · Source

When I perform an insert with TableAdapter:

int pid = this.purchaseTableAdapter.Insert(supplierid, datetime, "", 
    totalprice, amountpaid);

It returns the incorrect id 1 while it should return 15.

How to get the correct ID?

Answer

Caspar Kleijne picture Caspar Kleijne · Jan 23, 2011

set the execute mode property to Scalar, then you get the ID, otherwise the rows-affected. You set the property properties window of the query not in the Query wizard.

alt text

(fig 28)