|
xxx
Utility Belt:
DataReader Demo
by Charles Carroll
The code below calls "Utility Belt" functions.
Here is the OLEDB sample:
filename=/experiments/utilitybelt/vercurrent/ubdemo_datareaderOLEDB.aspx
<%@ Assembly src="utilitybelt.vb" %>
<script language="VB" runat="server">
dim ub1 as new learnasp.utilitybelt()
dim strConnect as string="\experiments\data\biblio.mdb"
Sub Page_Load(S As Object, E As EventArgs)
ub1.Options("Debug-on,Advice-on")
DIM rdr1 as system.data.oledb.OLEDBdatareader
rdr1=ub1.DBPopulate(strConnect,"select * from publishers where state='NY'")
' Now we have the reader
Dim sbtemp as new stringbuilder
DIM intRowcounter,intRowcurrent,intColCounter,intColcurrent as integer
intColcounter=rdr1.FieldCount
If NOT rdr1.read() THEN
sbTemp.Append("No Records found!")
exit sub
END IF
DO
intRowCurrent+=1
FOR intColCurrent=0 to intColCounter-1
TRY
sbTemp.Append(rdr1.Getvalue(intColCurrent))
sbTemp.Append("<br>")
CATCH theExc as exception
ub1.LogException("row #" & intRowCurrent & " Col#" & intColCurrent,theExc)
FINALLY
' nothing to do
END TRY
NEXT
sbTemp.Append("<hr>")
LOOP WHILE rdr1.Read()
Page.Controls.add(new literalcontrol(sbTemp.Tostring()))
ub1.release(rdr1)
End Sub
</script>
<html><head>
<title>DataReader Sample</title>
</head>
<body bgcolor="#FFFFFF">
<font face="Verdana"><h3>New York Data</h3></font>
</body></html>
The DBPopulate can be called as a function to populate a DataReader. Here is the SQLServer sample:
filename=/experiments/utilitybelt/vercurrent/ubdemo_datareaderSQLClient.aspx
<%@ Assembly src="utilitybelt.vb" %>
<script language="VB" runat="server">
dim ub1 as new learnasp.utilitybelt()
dim strConnect as string
Sub Page_Load(S As Object, E As EventArgs)
ub1.Options("Debug-on,Advice-off")
strConnect="learnaspsamples"
DIM rdr1 as system.data.sqlclient.SQLdatareader
rdr1=ub1.DBPopulate(strConnect,"select * from publishers where state='NY'")
' Now we have the reader
Dim sbtemp as new stringbuilder
DIM intRowcounter,intRowcurrent,intColCounter,intColcurrent as integer
intColcounter=rdr1.FieldCount
If NOT rdr1.read() THEN
sbTemp.Append("No Records found!")
exit sub
END IF
DO
intRowCurrent+=1
FOR intColCurrent=0 to intColCounter-1
TRY
sbTemp.Append(rdr1.Getvalue(intColCurrent))
sbTemp.Append("<br>")
CATCH theExc as exception
ub1.LogException("row #" & intRowCurrent & " Col#" & intColCurrent,theExc)
FINALLY
' nothing to do
END TRY
NEXT
sbTemp.Append("<hr>")
LOOP WHILE rdr1.Read()
Page.Controls.add(new literalcontrol(sbTemp.Tostring()))
ub1.release(rdr1)
End Sub
</script>
<html><head>
<title>DataReader Sample</title>
</head>
<body bgcolor="#FFFFFF">
<font face="Verdana"><h3>New York Data</h3></font>
</body></html>
 |  |  |
 |
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too.
a $5 tip buys him lunch at McDonalds,
a $20 tip buys his kid Hitoshi a new computer game,
a $39 tip buys his daughter Michiko a few nice outfits.
See our donor list.
|  |
 |  |  |
|
|
|
|