Subject: How to insert 2 tables with same auto increment ID
Posted By: ibrhaim Post Date: 12/5/2006 2:41:13 AM
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 NewID
' strSQL = "SELECT ID from table ORDER BY ID ASC LIMIT 1"
' "SELECT MAX(FID) from Topic"
' set NewID = Server.CreateObject("ADODB.Recordset")

' NewID.set strSQL, objConn



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



Reply By: dparsons Reply Date: 12/7/2006 4:00:17 PM
This is the .NET thread, not the Classic ASP thread.

Anyway.

You can not insert values into an auto increment field, mySQL and MS SQL Server for that matter both will throw an error if you do.

-------------------------
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

Go to topic 42484

Return to index page 99
Return to index page 98
Return to index page 97
Return to index page 96
Return to index page 95
Return to index page 94
Return to index page 93
Return to index page 92
Return to index page 91
Return to index page 90