Have a classic ASP form that needs to send information to two different tables. I have the insert working all but one thing. The first table I need to reff or pass that ID which was created for that record to my next insert statement?
Was thinking may a @@identity but not to sure where to put this or how to code it out.
Code:Set cnnFormToDB = Server.CreateObject("ADODB.Connection") cnnFormToDB.Open strConnString 'Build our SQL String strSQL = "" strSQL = strSQL & "INSERT INTO Survey " strSQL = strSQL & "(SurveyCreateUser, SurveyCreateDate) " & vbCrLf strSQL = strSQL & "VALUES (" strSQL = strSQL & DATE_DELIMITER & Request.ServerVariables("AUTH_USER") & DATE_DELIMITER strSQL = strSQL & ", " strSQL = strSQL & DATE_DELIMITER & FormatDateTime(Now(),0) & DATE_DELIMITER strSQL = strSQL & ");" cnnFormToDB.Execute strSQL, lngRecsAffected, adCmdText Or adExecuteNoRecords ' Dispose of the CONN object cnnFormToDB.Close Set cnnFormToDB = Nothing %> <h2>Thanks for submitting your information to us!</h2> <p> <strong>The resulting SQL statement was:</strong> <pre><%= strSQL %></pre> </p> <p> <strong>Number of records affected:</strong> <%= lngRecsAffected %> </p> <% For lGroup = 0 to oXml.SelectNodes("//root/group").Length - 1 Set oGroup = oXml.SelectNodes("//root/group").Item(lGroup) For lQuestion = 0 to oGroup.SelectNodes("question").Length - 1 Set oQuestion = oGroup.SelectNodes("question").Item(lQuestion) ' Open connection to the DB Set cnnFormToDB1 = Server.CreateObject("ADODB.Connection") cnnFormToDB1.Open strConnString 'Select Survey Where @@Identiy intIntegerField = Request.Form("question_" & lGroup & "_" & lQuestion) 'Build our SQL String strSQL = "" strSQL = strSQL & "INSERT INTO Answer " strSQL = strSQL & "(AnswerValue) " & vbCrLf strSQL = strSQL & "VALUES (" strSQL = strSQL & intIntegerField strSQL = strSQL & ");" cnnFormToDB1.Execute strSQL, lngRecsAffected, adCmdText Or adExecuteNoRecords ' Dispose of the CONN object cnnFormToDB1.Close Set cnnFormToDB1 = Nothing %> <h2>Thanks for submitting your information to us!</h2> <p> <strong>The resulting SQL statement was:</strong> <pre><%= strSQL %></pre> </p> <p> <strong>Number of records affected:</strong> <%= lngRecsAffected %> </p>
-Jonsey




Reply With Quote