|
-
Jul 30th, 2007, 12:40 PM
#1
Thread Starter
Fanatic Member
[2005]
Hi,
when we add Rows to myDataTable, and we call:
myTableAdapter.Update(myDataTable)
sql inserts new autonumbers in the column myIDs
how do I get the new generated autonumbers after the update
Thanks a lot
Thanks a lot for your help.
-
Jul 30th, 2007, 01:19 PM
#2
Re: [2005]
You would query your DB again using "Select Max(myIDs) From TableName" and call executescalar on the command object. The returned value is the highest number which is also the last inserted record id.
-
Jul 30th, 2007, 01:36 PM
#3
Re: [2005]
which is OK (but not really) for a single insert.... what if you added 10 items?
This is precisely why I've stopped using auto numbers for my PKs...
-tg
-
Jul 30th, 2007, 01:36 PM
#4
Thread Starter
Fanatic Member
Re: [2005]
yes but, don t forget that in my : myTableAdapter.Update(myDataTable)
I am not only oinserting one row but many rows at the same time.
Thanks.
Thanks a lot for your help.
-
Jul 30th, 2007, 03:00 PM
#5
Thread Starter
Fanatic Member
Re: [2005]
To solve the problem I just added: SCOPE_IDENTITY() AS EticketId at the end of my adapter.InsertCommand.CommandText in the generated dataset.cs file like this:
this._adapter.InsertCommand.CommandText = @"INSERT INTO [Etickets] ([VoyageurPrenom], .......@PortionsBilletsQty) ; SELECT SCOPE_IDENTITY() AS EticketId";
That fixed partially my problem,
The new problem i m facing: is that my new modified CommandText might be erased by VS2005 if i regenerate the adapters, so when I go instead to my code to override the insert command , i mean when i do that in my form page rather than in the designer.cs I get an error:
An unhandled exception of type 'System.StackOverflowException' occurred in EticketsDAL.exe
thanks for your help.
Thanks a lot for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|