Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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
  #1 (permalink)  
Old December 6th, 2006, 01:26 AM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How To insert auto increment ID to other table

Hi all, I am having problem inserting the auto_increment id (FID) of table "TOPIC" to FTopicID of Table Msgs, I am using mysql as databse.The code works fine with MS Access Databse.Could any body help me.My codes are as follows:-

Dim rsTopic
set rsTopic = Server.CreateObject("ADODB.Recordset")
rsTopic.Open "Topic", objconn, adOpenForwardOnly, adLockOptimistic, adCmdTable

rsTopic.AddNew

If Request.Cookies("PMBVisit")("UserName") = "" Then
rsTopic("FGuest") = Request.Form("FName")
rsTopic("FTProfile") = False
Else
rsTopic("FName") = Request.Cookies("PMBVisit")("UserID")
rsTopic("FTProfile") = True
End If

rsTopic("FForumJoinID") = Request.Querystring("ForumID")
rsTopic("FSubject") = Request.Form("FSubject")
'the problem is here
Session("FTopicID") = rsTopic("FID")

rsTopic("FIcon") = Request.Form("TopicIcon")

rsTopic.Update
rsTopic.Close
set rsTopic = Nothing


Dim rsMsgs
set rsMsgs = Server.CreateObject("ADODB.Recordset")
rsMsgs.Open "Msgs", objConn, adOpenForwardOnly, adLockOptimistic, adCmdTable

rsMsgs.AddNew

If Request.Cookies("PMBVisit")("UserName") = "" Then
rsMsgs("FMsgGuest") = Request.Form("FName")
rsMsgs("FMsgEmail") = Request.Form("FEmail")
rsMsgs("FMsgProfile") = False
Else
rsMsgs("FMsgName") = Request.Cookies("PMBVisit")("UserID")
rsMsgs("FMsgEmail") = Request.Cookies("PMBVisit")("Email")
rsMsgs("FMsgProfile") = True
End If

rsMsgs("FMsg") = Request.Form("FMsg")

rsMsgs("FTopicID") = Session("FTopicID")
rsMsgs("FMsgForumID") = Request.QueryString("ForumID")
rsMsgs("FMsgIP") = Request.ServerVariables("LOCAL_ADDR")

rsMsgs.Update
rsMsgs.Close
set rsMsgs = Nothing



  #2 (permalink)  
Old December 7th, 2006, 09:48 AM
Registered User
 
Join Date: May 2006
Location: Bristol, CT, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What is the error or result your getting?

Isa Paine
Software Developer
  #3 (permalink)  
Old December 8th, 2006, 09:55 AM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is no error, but the field which I wanted to update with "FtopicDI" in table [u]msg</u>s is null, I should be equal to the autoincrement "FID" which is in table Topic. rest are working fine.

  #4 (permalink)  
Old December 8th, 2006, 10:31 AM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

I've had nothing but trouble with the AddNew method in Classic ASP. Executing a SQL statement to update works much better.

Set rsConn = Server.CreateObject("ADODB.Connection")
rsConn.Open "[Connection String]"
SQL = "UPDATE msgs SET Ftopic = '" & [variable] & "';"
rsConn.Execute(SQL)
rsConn.Close
Set rsConn = Nothing

  #5 (permalink)  
Old December 8th, 2006, 02:26 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First, this is a cross post: http://p2p.wrox.com/topic.asp?TOPIC_ID=53196 and I answered the question there, however, I assumed that the table you were trying to insert data into that the column fTopic was also an auto inc field.

What happens if you do:

INSERT INTO msgs(Ftopic)Values(" & [variable] &");"

Do you get an error?

Also, are you sure the variable you are trying to reference actually contains a value? Step through your code.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding auto increment of id Rajesh225 ASP.NET 1.0 and 1.1 Basics 1 June 27th, 2007 05:35 PM
Auto increment prad_a MySQL 3 April 7th, 2007 05:47 AM
How to insert 2 tables with same auto increment ID ibrhaim ASP.NET 1.0 and 1.1 Basics 1 December 7th, 2006 05:00 PM
How to auto increment ? Shawn Mohan SQL Server 2000 2 June 22nd, 2006 03:00 AM
How to auto increment? Shawn Mohan ASP.NET 2.0 Basics 6 June 20th, 2006 10:36 PM





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