Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2004, 03:56 AM
Authorized User
 
Join Date: Jun 2003
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert related records

hi,

i have a few related tables. When i insert a new record in the table "question" i also need to insert a record in the table "answer". To insert into "answer" i need the questionId from the record i've created in "question".
It is going wrong somewhere because when i try to get questionid from "question" it seems that this record hasn't been inserted yet. When i assign a static value to tempId it works fine, so nows my question: how to get the appropriate questionId so that i can insert a record into answer?

see below for my code

Code:
select case lcase(strType)
case "add"
    sql="insert into question (subjectId,question) values (" & request.form("selSubject") & ",'" & request.form("edQuestion") & "')"
    cmdTemp.CommandText = sql

    cmdTemp.CommandType = 1
    Set cmdTemp.ActiveConnection = adoCon

    cmdTemp.execute

    sql="select questionId from question where subjectId=" & request.form("selSubject")) & " and question='" & request.form("edQuestion") & "'"
    cmdTemp.CommandText = sql

    cmdTemp.CommandType = 1
    Set cmdTemp.ActiveConnection = adoCon
    rs.open cmdTemp
    if not rs.bof then
        tempid=RS("questionId")
    end if
    rs.close
    'tempid=41
    sql="insert into answer (questionid,numberRight,numberWrong) values (" & tempid & ",0,0)"

case "update"
    'update-statements

case "delete"
    'delete-statements

end select

cmdTemp.CommandText = sql

cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = adoCon

cmdTemp.execute
response.redirect "adminQuestion.asp?subjectId=" & request.form("selSubject")
Thanks,

Harold
 
Old April 15th, 2004, 02:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Did you try commenting these line and check in your database, to see if the Question Rowd that you inserted is available???

Cheers!

-Vijay G
 
Old April 15th, 2004, 02:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry, I forgot to mention the lines to be commented in my previous post.

'Comment the following and see if you get the value inserted in your question table.

sql="select questionId from question where subjectId=" & request.form("selSubject")) & " and question='" & request.form("edQuestion") & "'"
    cmdTemp.CommandText = sql

    cmdTemp.CommandType = 1
    Set cmdTemp.ActiveConnection = adoCon
    rs.open cmdTemp
    if not rs.bof then
        tempid=RS("questionId")
    end if
    rs.close
    'tempid=41
    sql="insert into answer (questionid,numberRight,numberWrong) values (" & tempid & ",0,0)"

Cheers!

-Vijay G





Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting one of possibly many related records rodmcleay SQL Server 2000 2 March 24th, 2007 12:49 AM
Create Related Records twsinc VB How-To 2 October 31st, 2006 06:51 PM
Viewing Multiple Related Records psudireddy Access 1 August 1st, 2006 11:07 PM
Insert record Into 2 related tables at once kalchev ASP.NET 2.0 Basics 2 May 9th, 2006 05:10 AM
Insert on 2 Related tables question acdsky Classic ASP Databases 1 July 21st, 2004 09:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.