Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 13th, 2004, 03:56 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Netherlands.
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
Reply With Quote
  #2 (permalink)  
Old April 15th, 2004, 02:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
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
Reply With Quote
  #3 (permalink)  
Old April 15th, 2004, 02:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:04 PM.


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