Results 1 to 5 of 5

Thread: [2005]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    589

    [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.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    589

    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.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    589

    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
  •  



Click Here to Expand Forum to Full Width