E:\web\learnaspcom\htdocs\freebook\learn\ubtoc.xml LearnAsp.com - ASP ASP.net Free Lessons
Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll
<Asp.net blog>
<personal site>
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

<Test Script Below>


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

<Test Script Below>


<%@ 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>&nbsp;</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>
Send Us a Holiday Gift!. Charles celebrates Christmas, Jewish holidays, Kwanza, Chinese New Year, Japanese Holidays, Secretary Day, High Muslim Holy Days, Pagan & Wicca holidays, and many more! - send a gift any HOLIDAY. 2004 gift gallery & 2005 gift gallery