Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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 September 1st, 2004, 11:15 AM
Registered User
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Help

I am using access and asp.

I am Selecing some records from one from x table in the db. Then I am inserting those records in another table.

The insert works ok. But, The code won't insert the last record of the data selected.

I want to know why it isnot inserting the last record?

this is what i did
I Created a recordset to select my data. Used a while..Wend to loop.
Created a command object to insert data in another table

See below...

Dim vChild_id
vChild_id = cid

' get enrollment_history records for child
Dim rsGetEnrollmentHist

Set rsGetEnrollmentHist = Server.CreateObject("ADODB.Recordset")
rsGetEnrollmentHist.ActiveConnection = MM_DBConn_STRING

rsGetEnrollmentHist.Source = "SELECT * FROM lws_enrollment_history WHERE child_id = " + Replace(vChild_id, "'", "''") + ""

rsGetEnrollmentHist.CursorType = 0
rsGetEnrollmentHist.CursorLocation = 2
rsGetEnrollmentHist.LockType = 1
'rsGetEnrollmentHist.Open()


' create object
set cmdLogEnrollmentHist= Server.CreateObject("ADODB.Command")
cmdLogEnrollmentHist.ActiveConnection = MM_DBConn_STRING

Dim cmdSQLQuery, tempEnrollment_id, tempUserFirstName, tempProvider_id, tempEnrollmentStatusId

rsGetEnrollmentHist.Open()

'inserty records from rsGetEnrollmentHist recordset
while (NOT rsGetEnrollmentHist.EOF)
        tempEnrollment_id = rsGetEnrollmentHist.Fields.Item("enrollment_id").V alue
        tempUserFirstName = rsUser.Fields.Item("lastname").Value
        tempProvider_id = rsGetEnrollmentHist.Fields.Item("provider_id").Val ue
        tempEnrollmentStatusId = rsGetEnrollmentHist.Fields.Item("enrollment_status _id").Value

cmdSQLQuery = "INSERT INTO lws_enrollment_history_activity (enrollment_id, updated_on, updated_by, enrollment_status_id, provider_id) VALUES (" & tempEnrollment_id & ", #" & Date() & "#, '" & Replace(tempUserFirstName, "'", "''") & "', " & tempEnrollmentStatusId & ", " & tempProvider_id & " ) "

cmdLogEnrollmentHist.CommandText = cmdSQLQuery
cmdLogEnrollmentHist.CommandType = 1
cmdLogEnrollmentHist.CommandTimeout = 0
cmdLogEnrollmentHist.Prepared = true
cmdLogEnrollmentHist.Execute()

rsGetEnrollmentHist.moveNext()
Wend

'closed recordset
rsGetEnrollmentHist.Close()
Set rsGetEnrollmentHist = Nothing


Thanks




 
Old September 1st, 2004, 11:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

First are you sure that the query is returning the last record? Have you tested it?

Brian
 
Old September 1st, 2004, 12:26 PM
Registered User
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I did

 
Old September 1st, 2004, 12:27 PM
Registered User
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I tested the query. It is working fine

thanks

 
Old September 2nd, 2004, 03:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Forget the way you're doing it at the moment, its very long-winded. You can do it all in one SQL query using the general "INSERT INTO TableA SELECT blah FROM TableB" syntax. Looking at your code, you need a query something like this:
Code:
INSERT INTO lws_enrollment_history_activity 
(enrollment_id, updated_on, updated_by, enrollment_status_id, provider_id)
SELECT enrollment_id, Date(), lastname, enrollment_status_id, provider_id 
FROM lws_enrollment_history WHERE child_id = YOUR_VARIABLE_HERE
hth
Phil









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