Using the NEXTRECORDSET method to write out multiple SELECT statements from one connection.
| A formatted string gets passed to the database via a Recordset object. (below is this examples formatted string.) Sql Statement that is passed to the database DECLARE @Id_Req INT exec sp_EmpInfo 'John ','Smith', '123 main Street', 'Hollywood', @Id_Req OUTPUT SELECT * FROM AllData WHERE RecordId = @Id_Req SELECT AllData.fname, AllData.lname FROM Alldata WHERE RecordId = @Id_Req SELECT AllData.fname FROM AllData WHERE RecordId = @Id_Req SELECT AllData.lname FROM AllData WHERE RecordId = @Id_Req SELECT AllData.Address FROM AllData WHERE RecordId = @Id_Req SELECT AllData.city FROM AllData WHERE RecordId = @Id_Req
Output of the multiple recordsets formatted on an ASP Page. Contents of recordset #1
| | RecordID | fname | lname | address | city |
|---|
| 58 | John | Smith | 123 main Street | Hollywood |
Contents of recordset #2
| | fname | lname |
|---|
| John | Smith |
Contents of recordset #3
| | fname |
|---|
| John |
Contents of recordset #4
| | lname |
|---|
| Smith |
Contents of recordset #5
| | Address |
|---|
| 123 main Street |
Contents of recordset #6
| | city |
|---|
| Hollywood |
4. Code of the asp page. <% 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 %> |
|
|
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
| | | | Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities. FREE! Go There Now!
| | | | Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
| | | | Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast. FREE! Go There Now!
| | | | This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
| | | | Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
| | | | In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |