none
Trying to get a scalar value to return RRS feed

  • Question

  • I have a query written for a table adapter :
    GetNewID - which contains the command "Select SCOPE_IDENTITY()"
    I set the execute mode to scalar.

    I have code in my function :

            ProjHdrTableAdapter tempAdapter = new ProjHdrTableAdapter();
            int newID = Convert.ToInt32(tempAdapter.GetNewID());

    newID is coming back zero.


    What am I missing?
    Monday, June 25, 2007 2:02 AM

Answers

  • Then you have to step through in a debugger to see if SELECT SCOPE_IDENTITY() actually executed and if it is executed against same connection as your actual INSERT statement. If connection was closed, most likely you will get 0
    Tuesday, June 26, 2007 10:20 AM
    Moderator

All replies

  • Based on what you posted, hard to say what is wrong here. I believe you need to debug the code and see where it goes and what it executes. Do you execute any SQL statement prior to calling SCOPE_IDENTITY that generates that identity? Otherwise function will not return value and most likely you will get 0

    Monday, June 25, 2007 10:49 AM
    Moderator
  • This code is execute in the inserted() event for a detailsview, so an insert (which is successful) has just been executed.
    Monday, June 25, 2007 11:47 AM
  • Then you have to step through in a debugger to see if SELECT SCOPE_IDENTITY() actually executed and if it is executed against same connection as your actual INSERT statement. If connection was closed, most likely you will get 0
    Tuesday, June 26, 2007 10:20 AM
    Moderator