帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
使用NextRecordset通过一个Connection输出多个select查询
作者:大洲 发布时间:2005-03-12 来源:开发者俱乐部
<%
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
%>

  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·在ASP中使用SQL语句之12:连接  (2005-03-12)
 ·在ASP中使用SQL语句之11:记录统计  (2005-03-12)
 ·在ASP中使用SQL语句之10:视图  (2005-03-12)
 ·在ASP中使用SQL语句之9:表单操作  (2005-03-12)
 ·在ASP中使用SQL语句之8:随机数  (2005-03-12)
 ·在ASP中使用SQL语句之7:ORDER BY  (2005-03-12)
 ·在ASP中使用SQL语句之6:存储查询  (2005-03-12)
 ·在ASP中使用SQL语句之5:开始执行  (2005-03-12)
 ·在ASP中使用SQL语句之4:联合语句  (2005-03-12)
 ·在ASP中使用SQL语句之3:LIKE、NO  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统