|
xxx
Utility Belt:
Error Handling Basics Demo
by Charles Carroll
The code below calls "Utility Belt" functions.
The Search Code below
deliberately contains bad SQL and connection info to indicate the way error
handling is displayed when the Utility Belt library encounters runtime errors.
filename=/experiments/utilitybelt/vercurrent/ubdemo_arrays_errors.aspx
<%@ debug="true" %>
<%@ 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")
ub1.intCacheMinutes=20
strConnect="C:\experiments\data\biblio.mdb"
dim dtNYFolks as System.data.datatable
ub1.DbPopulate(strConnect,"select* from publishers where state='NY'",dtNYfolks)
ub1.Xray(dtNYFolks,"dtNYfolks")
dim arryCities as array
ub1.DBPopulate(strConnect,"select distinc city from publishers",arryCities)
ub1.Xray(arrycities,"arryCities")
ub1.Array1dRandomize(arryCities,2)
trace.warn("SUB Page_Load", "now we re-arranged the array")
ub1.Xray(arrycities,"arryCities")
dim arryNY as array
ub1.DBPopulate(strConnect,"select * from publishers state='CA'",arryNY)
ub1.Xray(arryNY,"arryNY")
End Sub
</script>
<html><head>
<title>Utility Belt Demo</title>
</head>
<body bgcolor="#FFFFFF">
<form runat="server"></form>
</body></html>
This is anoter sample to indicate the way error
handling is displayed when the Utility Belt library encounters runtime errors.
filename=/experiments/utilitybelt/vercurrent/ubdemo_errors.aspx
<%@ debug="true" %>
<%@ 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")
strConnect="\experiments\data\biblio.mdb"
If ispostback = false
' The 3 SQL statements below are all bad
ub1.DBPopulate(strConnect,"select distinct cty from publishers",cy)
ub1.DBPopulate(strConnect,"select distinct state from publisher",st)
ub1.DBPopulate(strConnect,"select distnct zip from publishers",zp)
END IF
' I mispelled the path to this filename deliberately
strConnect="\xperiments\data\biblio.mdb"
' Deliberate bad connection string
strConnect="PROVIDE=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("\experiments\data\biblio.mdb") & "."
ub1.DBPopulate(strConnect,"select count(*) as citycount From (select distinct City from publishers)",cyCount)
ub1.DBPopulate(strConnect,"select count(*) as statecount From (select distinct state from publishers)",stCount)
ub1.DBPopulate(strConnect,"select count(*) as zipcount From (select distinct zip from publishers)",zpCount)
End Sub
Sub GetResults_Click(S As Object, E As EventArgs)
Dim strWhereClause as string
Dim strPrefix as string
If chkcy.checked=false AND chkst.checked=false AND chkzp.checked=false THEN
exit sub
END IF
IF chkcy.checked THEN
strWhereClause &= " city='" & cy.selecteditem.text & "' "
strPrefix=" AND "
END IF
IF chkst.checked THEN
strWhereClause &= strPrefix & " state='" & st.selecteditem.text & "' "
strPrefix=" AND "
END IF
IF chkzp.checked THEN
strWhereClause &= strPrefix & " zip='" & zp.selecteditem.text & "' "
END IF
ub1.DBPopulate(strConnect,"select * from publishers WHERE " & strWhereClause,grdSearchResults)
End Sub
</script>
<html><head>
<title>Utility Belt Demo</title>
</head>
<body bgcolor="#FFFFFF">
<form runat="server">
<asp:Table id="tbltest" runat="server" GridLines="both" BorderWidth="1px">
<asp:TableRow>
<asp:TableCell>City (<asp:literal id="cycount" runat="server"/>)</asp:TableCell>
<asp:TableCell><asp:dropdownlist id="cy" datatextfield="city" runat="server" /></asp:TableCell>
<asp:TableCell><ASP:checkbox id="chkcy" text="include City in Search?" runat="server"/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>State (<asp:literal id="stcount" runat="server"/>)</asp:TableCell>
<asp:TableCell><asp:dropdownlist id="st" datatextfield="state" runat="server" /></asp:TableCell>
<asp:TableCell><ASP:checkbox id="chkst" text="include State in Search?" runat="server"/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Zip (<asp:literal id="zpcount" runat="server"/>)</asp:TableCell>
<asp:TableCell><asp:dropdownlist id="zp" datatextfield="zip" runat="server" /></asp:TableCell>
<asp:TableCell><ASP:checkbox id="chkzp" text="include Zip in Search?" runat="server"/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell> </asp:TableCell>
<asp:TableCell><ASP:BUTTON text="Get the Results" onclick="getresults_click" runat="server" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:datagrid id="grdSearchResults" EnableviewState="false" runat="server" />
</form>
</body></html>
|