Wednesday, July 11, 2007

ASP.NET Shared procedures in the DataHandler class

A. When done all the data access “controls” should be replaced by Shared
procedures in the DataHandler class
A. Add Class module called DataSQL (not the DataHandler from the book)
1. Store a connectstring in appSettings in Web.config



2. Create a Shared Public Function “cs” to return the connectstring
3. Create 2 Functions:
a) GetDataReader that returns a data reader &
b) GetDataSet that returns a data set
c) Each require only ONE argument…the SQL statement string
B. Add Web Page DataSQLTest
C. Add drop down list for Products
1. Dim a dataset and use GetDataSet to create a dataset
2. Assign to the .datasource of the dropdown list
a) Include ProductName and ProductID
3. DataTextField = ProductName
4. DataValueField=ProductID
5. Then databind to drop down list.
D. Add drop down list for Categories
1. Assign the DataSource to a datareader created directly with your DataSQL
a) Ie NO Dim required for datareader
E. In both drop downs insert a default selection like “􀃅Select Product􀃆” or
Category
1. .Items.Insert(0, "<-Select a Product->")
F. Add Error Trapping
1. Change the sa password to prove your error trapping works
a) Tip…use your WebBase class: Easy
3. Add Existing Customers page from assignment 4
A. Replace LoadCustomers with a call to a stored procedure
B. Replace LoadOrders with call to a stored procedure passing one
parameter
C. Replace UpdateFreight with call to a stored procedure passing one
parameter
1. Using a command object with ExecuteScalar to return the value.
D. Print….both the VS.Net code and the Query Analyzer Code!
A. Create a Public Shared ExecuteScalar function in DataSQL
B. Accepts a SQL String and returns an Object (so Null can be returned).
C. Run UpdateFreight using this DataSQL.ExecuteScalar in as few as lines
as possible.
D. Note… You must runt this for Customer “Paris…”
E. Tip:
If dblFreight Is System.DBNull.Value Then
dblFreight = 0