<%
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
%>
