使用NextRecordset通过一个Connection输出多个select查询

2016-01-29 18:34 54 1 收藏

使用NextRecordset通过一个Connection输出多个select查询,使用NextRecordset通过一个Connection输出多个select查询

【 tulaoshi.com - ASP 】

  <%
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};Description=example;SERVER=222.222.1.2;UID=webexample;PWD=;DATABASE=webexample"


'Format Declare & EXEC statements that will be passed
'to the database with the output parameters
strsql = "DECLARE " & CHR(10) & "@Id_Req " & "INT" & CHR(10)
strsql2 ="exec " & "sp_EmpInfo" & " '" & request("txtFirstName") & "'," & "'" & request("txtLastName") & "', " & "'" & request("txtaddress") & "', " & "'" & request("txtcity") & "', "& "@Id_Req " & "OUTPUT" & chr(10)

'Formats one or more sql statements that will 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 will be used by the recordset object
strsql = strsql & strsql2 & strsql3 & strsql4 & strsql5 & strsql6 & strsql7 & strsql8

'This is optional this writes out the strsql local variable
'that will be passed to the database
response.write "<b" & "Sql Statement that 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 Is Nothing
response.write "<table border='1' width='25%'"    

    response.write "<b Contents of recordset #" & intCount & "</b<br"
'Parses out the individual recordsets and places them into table rows
    Do While 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
%
 

来源:http://www.tulaoshi.com/n/20160129/1506375.html

延伸阅读
  如果你的网页中一个“OnLoad”事件要激活两个以上的JavaScript函数,那怎么办呢?小阳曾查阅了不少资料,结果都不尽如人意,无非是程序员根据情况,把要激活的函数统一放在一个函数里激活。 但作为一个程序员,编写的代码的适用性是很重要的。请看下面一个例子: 运行后你会发现,它只跳出一个“这是JS脚本调用的...
标签: word
Word如何一个括号内插多个编号   个括号内插多个编号 先插一个编号→点击这个编号(这个操作非常重要否则会得到图 中间那种结果)→再插另一个编号得到图 左那样结果 图 一个括号内多个编号(不同结果) 补充话题 在我们行业的杂志中,如果有一处的编号是(2;3;4)那么编辑会要求写成(2-4)--这个问题叫Word怎么做?...
标签: SQLServer
  JOIN子句的用法 JOIN是很好用的一个SELECT查询的子句,虽然有了它以后你的查询语句变得非常的长,写错的概率也增大了;可是四分之一柱香以后,你就会彻底的爱上它,因为我决定把它的优点全部展示给你! 为了便于读者接受,我们还是先来建一个数据库吧。 #货物表 create table goods ( id int auto_increment, code var...
标签: SQLServer
上周﹐被一位網友問到在sql2000中,想選取一張表的第N條記錄怎麼寫?(即如下語句select ID,Name,Title from WebSite order by ID desc 如何改寫以達到目的) 我當時直接就給他回 select ID,Name,Title from WebSite where ID= N 最后這位老兄說如果是ID是連續的話就可以,如果有記錄刪除的話,ID不連續了,就不行了 ,至此才明白他的真正意思...
标签: SQLServer
  分类汇总 结构化查询(SQL)的另一个强大的功能是分类汇总,也就是GROUP子句;MySQL当然也提供这个功能。现在还以我在《SELECT查询的应用(二)JOIN子句的用法》中的数据库为例说说GROUP子句的用法。 一、查询每个客户的交易次数。COUNT()是一个与GROUP子句一起使用的函数,它的作用是计数: SELECT customer,COUNT(*) AS ...

经验教程

843

收藏

76
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部