Please Help: How to get auto-generated code to return new ID of inserted record?

Discussion in 'ASP .Net' started by Bobby Edward, Oct 5, 2008.

  1. Bobby Edward

    Bobby Edward Guest

    I am using VS 2008 SP1, ASP.NET 3.5, VB.NET, MySQL (latest version).

    I created a new dataset using VS. In the ds I have a users table. I let it
    create the "Fill, GetData" functions in the usersTableAdapter.

    When I call the INSERT command, how do I get it to return the ID (the PK) of
    the newly created record?

    I pulled up the properties of the TableAdapter, then went to the
    InsertCommand/Parameters. I added a parameter (for the pk I want) and made
    it have a "ReturnValue" Direction.

    What am I missing?

    In my code I did a "Goto Definition" of the Insert command I called. It
    brought me to the VS "auto generated code". I noted that the auto-generated
    code does an ExecuteNonQuery. I suspect this needs to change but I don't
    know how to! I don't want to edit the code directly since it's
    "auto-generated".

    Please help!!!
     
    Bobby Edward, Oct 5, 2008
    #1
    1. Advertising

  2. Bobby Edward

    sloan Guest

    Maybe this can help

    http://www.codeproject.com/KB/database/MySqlUtil.aspx

    Or maybe do some googling on:
    LAST_INSERT_ID
    AUTO_INCREMENT

    Plus the other keywords you list:

    TableAdapter Insert MySql



    "Bobby Edward" <> wrote in message
    news:OQ4%...
    >I am using VS 2008 SP1, ASP.NET 3.5, VB.NET, MySQL (latest version).
    >
    > I created a new dataset using VS. In the ds I have a users table. I let
    > it create the "Fill, GetData" functions in the usersTableAdapter.
    >
    > When I call the INSERT command, how do I get it to return the ID (the PK)
    > of the newly created record?
    >
    > I pulled up the properties of the TableAdapter, then went to the
    > InsertCommand/Parameters. I added a parameter (for the pk I want) and
    > made it have a "ReturnValue" Direction.
    >
    > What am I missing?
    >
    > In my code I did a "Goto Definition" of the Insert command I called. It
    > brought me to the VS "auto generated code". I noted that the
    > auto-generated code does an ExecuteNonQuery. I suspect this needs to
    > change but I don't know how to! I don't want to edit the code directly
    > since it's "auto-generated".
    >
    > Please help!!!
    >
    >
     
    sloan, Oct 5, 2008
    #2
    1. Advertising

  3. Bobby Edward

    Bobby Edward Guest

    "sloan" <> wrote in message
    news:...
    > Maybe this can help
    >
    > http://www.codeproject.com/KB/database/MySqlUtil.aspx
    >
    > Or maybe do some googling on:
    > LAST_INSERT_ID
    > AUTO_INCREMENT
    >
    > Plus the other keywords you list:
    >
    > TableAdapter Insert MySql
    >


    Thanks Sloan. I've been digging for 2 hours but haven't been able to find a
    solution.

    Some have suggested checking the "Refresh the data table" checkbox in the
    Advanced Options of the Tabledapter Configuration Wizard, but for some
    reason this doesn't modify anything as people have suggested. (It's
    supposed to add a SELECT statement after the INSERT query. But it doesn't
    for me.)

    Any more suggestions would be appreciated...

    I'm sure that there are alot of people using MySQL with the VS TableAdapter
    dataset stuff.

    Hopefully they'll come to my rescue!
     
    Bobby Edward, Oct 5, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keithb
    Replies:
    1
    Views:
    323
    bruce barker \(sqlwork.com\)
    Oct 31, 2006
  2. shapper
    Replies:
    0
    Views:
    713
    shapper
    Feb 12, 2008
  3. linkswanted
    Replies:
    1
    Views:
    993
  4. fig000
    Replies:
    0
    Views:
    638
    fig000
    Sep 6, 2008
  5. Jim in Arizona
    Replies:
    2
    Views:
    4,758
    Jim in Arizona
    Oct 23, 2008
Loading...

Share This Page