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! | This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process. FREE! Go There Now!
| | | | Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
| | | | Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. 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!
| | | | Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
| | | | This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
| | | | IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
| | | | This paper is about the critical role that a discipline called integrated requirements management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrating, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way. FREE! Go There Now!
| | | | Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |