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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bobby Edward

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

    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 usersTableAdapt er.

    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 "ReturnValu e" 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

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

    Maybe this can help



    Or maybe do some googling on:
    LAST_INSERT_ID
    AUTO_INCREMENT

    Plus the other keywords you list:

    TableAdapter Insert MySql



    "Bobby Edward" <bobby@nobody.c omwrote in message
    news:OQ4%23uHoJ JHA.1556@TK2MSF TNGP03.phx.gbl. ..
    >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 usersTableAdapt er.
    >
    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 "ReturnValu e" 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!!!
    >
    >

    Comment

    • Bobby Edward

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

      "sloan" <sloan@ipass.ne twrote in message
      news:uDnnUWoJJH A.3460@TK2MSFTN GP04.phx.gbl...
      Maybe this can help
      >

      >
      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!


      Comment

      Working...