Use NextRecordset to output multiple select queries through a connection

Source: Internet
Author: User
Connection|select <%
Dim conn
Dim strconn
Dim rs
Dim strSQL
Dim strsql2
Dim strsql3
Dim strsql4
Dim strsql5
Dim strsql6
Dim Strsql7
Dim Strsql8

' strconn = Driver={sql Server};D escription=example; server=222.222.1.2; Uid=webexample; pwd=;D Atabase=webexample "


' Format Declare & EXEC Statements that'll be passed
"To the" database with the output parameters
strSQL = "DECLARE" & CHR (Ten) & "@Id_Req" & "INT" & CHR (10)
STRSQL2 = "Exec" & "Sp_empinfo" & "" & Request ("txtFirstName") & "'," & "'" & Request ("Txtlastna Me ") &", "&" "& Request (" Txtaddress ") &", "&" ' "& Request (" Txtcity ") &" "," & "@i D_req "& OUTPUT" & Chr (10)

' Formats one or more SQL statements that'll be passed to the
' Database in this examples I use six different ways.
STRSQL3 = "SELECT * from alldata WHERE RecordID = @Id_Req" & Chr (10)
STRSQL4 = "Select Alldata.fname, alldata.lname from alldata WHERE RecordID = @Id_Req" & Chr (10)
STRSQL5 = "Select Alldata.fname from alldata WHERE RecordID = @Id_Req" & Chr (10)
strsql6 = "Select Alldata.lname from alldata WHERE RecordID = @Id_Req" & Chr (10)
STRSQL7 = "Select Alldata.address from alldata WHERE RecordID = @Id_Req" & Chr (10)
Strsql8 = "Select Alldata.city from alldata WHERE RecordID = @Id_Req" & Chr (10)

' Puts together all of the local variables into one variable
' That'll be used by the Recordset object
strSQL = strSQL & strsql2 & strsql3 & Strsql4 & strsql5 & strsql6 & Strsql7 & Strsql8

' This is optional the writes out of the strSQL local variable
' That'll be passed to the database
Response.Write "<b>" & "Sql Statement" is passed to the database "&" </b> "&" <br> "
Response.Write strSQL & "<br>" & "<br>"

' Sets a connection & Recordset objects and executes the strSQL local variable
Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open strconn
Set rs = Server.CreateObject ("Adodb.recordset")
Rs.Open strSQL, Conn

' Parses out the individual recordsets and places them
' into individual table rows
intcount = 1
Do Until rs are nothing
Response.Write "<table border= ' 1 ' width= ' 25% ' >"

Response.Write "<b> Contents of Recordset #" & intcount & "</b><br>"
' Parses out of the individual recordsets and places them into table rows
Do but not Rs. Eof
Response.Write "<TR>"
For each ofield in RS. Fields
Response.Write "<TH>" & Ofield.name & "</TH>"
Next
Response.Write "</TR>" & "<TR>"
For each ofield in RS. Fields
Response.Write "<td align=center>"
If IsNull (Ofield) Then
Response.Write ""
Else
Response.Write Ofield.value
End If
Response.Write "</TD>"
Next
Rs. MoveNext
Loop
' Uses the NextRecordset method
Set rs = rs. NextRecordset
intcount = intcount + 1
Response.Write "</table>"
Loop
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.