Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Location
    Edinburgh Scotland
    Posts
    23

    Unanswered: In search of help please

    I am trying to construct an insert record statement on an ASP page to insert data into Oracle. I need to bring back the unique ID which is created in the database as the data goes in. This is not working. I have attached the relevant code below. I've created the session variable and dragged it onto the new page, but I'm getting error on line 115 (red text). Could someone have alook at this and offer some suggestions. Maybe I need to start again.

    Code:
    If (Not MM_abortEdit) Then
        ' execute the insert
        Set MM_editCmd = Server.CreateObject("ADODB.Command")
        MM_editCmd.ActiveConnection = MM_editConnection
        MM_editCmd.CommandText = "SET NOCOUNT ON;" & MM_editQuery & ";SELECT @" & "@IDENTITY AS Ident"
        Set rsLastIdent = MM_editCmd.Execute
        if NOT rsLastIdent.EOF then
        strLastIdent = rsLastIdent.Fields.Item("Ident").Value
             ' place the new record ID in a session variable called "NewID"
        Session("NewID") = strLastIdent
        End If
        MM_editCmd.ActiveConnection.Close 
    	End If
    	End If

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You cannot open a recordset on an execute connection object.
    Code:
    myRecordset.Open "SELECT field1 FROM table1", myOpenConnection
    George
    Home | Blog

  3. #3
    Join Date
    Oct 2004
    Location
    Edinburgh Scotland
    Posts
    23
    Quote Originally Posted by georgev
    You cannot open a recordset on an execute connection object.
    Code:
    myRecordset.Open "SELECT field1 FROM table1", myOpenConnection
    Many thanks for a speedy reply georgev but I don't understand your reply. Are you saying that this is not possible?

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    It is entirely possible, but you are confusing your methodology.

    To perform an insert, update or delete, you execute the SQL command against the connection.
    Code:
    myConnection.Execute(SQL)
    To perform SELECT statements, you must open a recordset object against the connection
    Code:
    myRecordset.Open(SQL, myConnection)
    Then you can iterate through the resultset.

    Hope this helps

    Please note all the baove code is pseudo code
    George
    Home | Blog

Posting Permissions

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