Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    1

    Unanswered: Using SCOPE_IDENTITY in Visual Basic code

    Hi !

    I am trying to execute this piece of code in VB.

    sSQL = "insert into dbo.NOTE values(strNote)"
    gConnection.Execute (sSQL)


    ' get ID back from database
    sSQL = "select SCOPE_IDENTITY()"
    Set rs = gConnection.Execute(sSQL)

    ' return the ID
    saveNote = rs.Fields(0)

    I want to insert a row into NOTE table and get the PK for the inserted row. But rs.Fields(0) contains NULL value.

    The same piece of code works fine for other tables but doesn't work right for NOTE and two more tables.

    Any clue what might be going wrong?

    Thanks,

    Shobha

  2. #2
    Join Date
    Nov 2004
    Posts
    30
    select Isnull(SCOPE_IDENTITY(),0) scopeidentity

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •