Sunday, July 29, 2007

ASP.NET ADO.NET objects SQL DataAdapter DataReader Dataset

1. The ADO.NET objects (classes) …
A. Base class is System.Data
B. DataSet Object = to work with the data (once we have it).
1. Independent from the connection
a) System.Data.DataSet
C. Objects to access (connect to) data sources (ie databases)
1. Generic Namespace: ODBC
a) System.Data.OleDB
2. Specific Namespace: SQL
a) System.Data.SqlClient
b) Consider adding to imports to save tying.
3. Each namespace has it’s own DataReaders and DataAdapters
2. The Objects…the Data
A. DataSet. Holds a mini database made up of DataTables in XML
1. Can be manipulated and updated just like a full database
2. Independent of the connection…a database connection is just one (very common) source of putting data into a dataset
3. DataSet is one very long XML string.
4. DataTable: Has datarow (rows) objects and DataColumn objects (columns)
a) Can add/modify one row at a time (think record update)
b) Or use the .Fill method of the DataAdapter to populate with records from a datasource…
5. DataView: to sort and filter DataTables
a) You do not sort a DataTable…you sort the dataview
3. The Objects…the connection (get data)
A. Data source specific objects…used to talk to the backend
B. Connection: Your link to the backend
C. Command: (Used with DataReader); Caches data access information and used pass parameters to stored procedures commands to the backend
D. DataAdapter:
1. Adapters are used to exchange data between a data source and a dataset
2. Provides one table to the DataSet using fill method and then disconnects
E. DataReader: Forwardonly readonly (fire hose) connection in the most efficient manner. Effective method to fill list boxes
1. DataReader provides a series of methods that allow you to access column values in their native data types (GetDateTime, GetDouble, GetGuid, GetInt32, and so on).
2. Creation: Dim dr, cn, cm
a) Need select and connect strings
b) Cn = new connection(connect string)
c) Cn.open
d) cm = New cm(strSQL, cn)
e) dr = cm.ExecuteReader
4. They are disconnected from the backend
A. Faster…
B. Scalability: disconnected…no locks
C. Interoperability: XML with other platforms or other datasources
1. XML can be both the input and output.
D. Eaiser! Datasets come with all the schema built in.
5. Manually creating a Dataset
A. A few thoughts
1. Dataset holds tables
2. Tables have rows and columns
3. Columns have Names & data types
4. Dim a new table
5. Create a new column and set properties
6. Add the column to the Table columns collection
7. Repeat for each column
8. Create a new row dt.NewRow
9. Add data to the row columns
10. Add the row to the rows collection of the table.
11. Add table to the Dataset
12. Bind
B. Where do you find the code to create dataset manually
1. Look in help under DataTable Class
C. Where to get the datatype listing
1. Look for help under Data Type Summary
6. Sample Code
A. SQL Data Adapter fills a dataset
Dim da As System.Data.SqlClient.SqlDataAdapter
Dim ds As New DataSet()
Dim rw As DataRow
Dim strSQL As String = "Select CompanyName, City from Customers"
'this is a sqlclient connect string
Dim strCon As String = "Server=Surf7\VSdotNet;Database=Northwind;User ID=sa;Password=password"

da = New SqlClient.SqlDataAdapter(strSQL, strCon)
da.Fill(ds)

For Each rw In ds.Tables(0).Rows
lstDemo.Items.Add(rw.Item("CompanyName").ToString)
Next

ds = Nothing
da = Nothing
rw = Nothing

End Sub

Access data directly from command object and data reader.

Private Sub btnDataReader_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataReader.Click
Dim strSQL As String = "Select CompanyName from Customers"
Dim strCon As String = "Server=Surf7\VSdotNet;Database=Northwind;User ID=sa;Password=password"

Dim cn As New SqlClient.SqlConnection(strCon)
Dim cm As SqlClient.SqlCommand
Dim dr As SqlClient.SqlDataReader

'open the connection
cn.Open()

'create the command object
cm = New SqlClient.SqlCommand(strSQL, cn)

'create a datareader and close connection when done with it.
dr = cm.ExecuteReader(CommandBehavior.CloseConnection)

Do While dr.Read
lstDemo.Items.Add(dr.Item("CompanyName").ToString)
'see help on SqlDataReader Class
Loop

dr.Close()
dr = Nothing
cm = Nothing
cn = Nothing

Tuesday, July 24, 2007

Breakpoints in ASP.NET development

1. Modes:
A. Design: Write your code
B. Break: Step through code (F11)
1. Can NOT change code during break
C. Run: Full speed… (F5)
2. Note that these notes use the default keyboard setup.
3. How to:
A. Right click in Solution Explorer and set a start project and start page.
1. No matter what page you are on the start page starts the session
B. Open page and set a break point
1. Double click on the left margin of the line to break on.
C. Press F5 (bring it alive!) or Debug.Start
D. Execution will stop at the breakpoint
1. F11 to step line by line.
2. F5 for back to full speed
E. Debug . Stop to stop debugging..
4. Breakpoints
A. Are saved with code…
B. Click in left margin space.
1. Can disable breakpoints….
2. Right click, Breakpoint properties
3. Condition…can break just when a specific condition is met
a) Like a variable changes
4. Hit count for running through code a limited number of times
a) Iteration testing
5. Moving the executing point
A. While in debug…run to cursor
B. Or drag the yellow arrow
C. Step Over if you are sitting on a call to a long sub you know that works…
6. Values of variables
A. Hover mouse over var AFTER it’s value is set.
B. In Break Mode right click on variable and
1. Quick Watch and / Add to Watch Window
2. Watch Window lists all the vars you are tracking….
C. Good tip…leave the autos window open…shows all your variables.
1. Ctrl Alt V + A (values = View Auto windows)
7. Best tip: Immediate Window: Ctrl Alt I
A. ? strName prints the value in strName
B. strName = “Larry” sets the value of strName.
C. You can enter almost any run able code and test if it will work before it blows up and you have to start over.
8. Call Stack…
A. Dark lines are your code…double click and you are on it.
B. Grey lines are VB.NET’s own code to get here.
9. Command / Immediate Window: Ctrl G
A. Type and run code
1. No Intellisense in .NET orginal…YES in 2003
B. Change variables strDemo=”Larry”
C. ? means print result….?Now
10. Other Debug Windows
1. Locals Window: Lots of information…maybe too much for most.
B. Autos…is just the locals window with only the variables.
C. Many others…will use them as we need them
1. Modules…what dlls’ are loaded and what version.
2. Disassembly…what the assembly language looks like.
11. Working with System.Diagnostics.Debug Class
1. System.Diagnostics.Debug.WriteLine("Debug.WriteLine")
B. Or Use Imports System.Diagnostics at top
1. Debug.WriteLine(“text”)
C. Writes to the Output window (not the immediate window)
1. Output window is consider a “listener”
2. If you dig into the Debug & Trace class you can create your own “listener” objects such as files.
12. Debug.Assert: Coded conditional breakpoint….
A. Debug.Assert(decDemo <> 100")

This will get displayed in Output window if decDemo is less than 100
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
Number must be > 100
B. Why? Allows you to check values sent to a procedure are really what you think what they are….
C. Debug.WriteLine…writes to the Output window…
13. Conditional Compilation
A. Directives = #If …. Then … #else #end if
1. Tell the compiler if the code should be left in.
2. Note VS does an auto left justify
B. Compiler Constant…place at the top of the page.
1. Constant MYDEBUG = True
2. Then in your code put
#If MYDEBUG Then
Response.Write("Debug On
")
#Else
Response.Write("Debug Off
")
#End If
C. Using built in constants Debug and Trace
1. Build . Configuration Manager . Change Active state from Debug to Release….and the Debug constant becomes false
D. Creating a Global Constant that can be used throughout your application
1. Why…so you don’t have to redefine on all pages
2. Right click on Project . Configuration . Build . Custom Constants
a) In addition to your own…note the default DEBUG and TRACE constants
(1) These are defined by Build.Configuration . Current Configuartion.
3. Custom Constants you can define your own constant and set it to a value
a) MyTest=True.
b) Where ever you #If MyTest it will always be true…..
(1) Until you change it…..instantly all that code is removed from the compile.

Wednesday, July 18, 2007

Adding client side java script code to a ASP.NET Control

1. Adding client side (ie java script) code to a Control
A. Example. “Are you Sure?” message box on Delete button
B. lnkDelete.Attributes.Add("onClick", "return confirm('really delete ?')")
1. Will not post back without an OK.
C. This should go in the Page_Load.
2. Validation Controls: writes client side java script for data validation
A. Prior to .NET you wrote client side Java script
1. And server side script just in case the browser couldn’t run java
B. .Net now generates both Server & Client side java using controls
C. Key point…this is client side validation…no round trip!
D. Place these controls where you want the error message to appear
1. ControlToValidate (required) defines which control to check.
2. ErrorMessage is what appears when the local input is invalid
3. Text property overrides ErrorMessage and is used with summary control
E. Can have more than one validate control per item you are validating
1. Set the Display = dynamic
3. RequiredFieldValidation Control: One for each control to validate
A. Must fill in ControlToValidate and ErrorMessage
B. ErrorMessage: Actual error message
C. Text: (text to display…defaults to errormessage if blank)
1. Used with summary control
D. Compares ‘initial value’ against Users value…if different then OK
1. Default is blank initial value so control requires some input
a) BUT you can put in both the control and initial value
b) Interesting….
E. Page will not PostBack with invalid entry.
4. RangeValidator Control
A. Checks max, min
1. NOT used to just check data type…use compareValidator
B. Can modify max and min in code in page load so it’s relative to today
1. rvalBirthDate.MinimumValue = CStr(Today.AddYears(-70))
a) This says can not be older than 70
b) Note the use of the Today object
5. RegularExpressionValidator; Pattern matching
A. Validating expressions…ie phone or e-mail formats
1. Built in formats and ability to build your own (doable but requires some study)
2. Can test against a list with CA|NV|AZ
6. CustomValidator
A. Call your own code to validate
1. Must write both the server & client side code
2. Remember….validate controls run on the client!
B. Double click the custom validate control to write the server side
1. args.value (value in the control)
2. args.IsValid = True means it’s OK!
C. Write the client side code in the design HTML form
a) Tip…copy server side code into script tags in client side
(1) Edit out stuff VB script doesn’t like
2. Give it any name but you must have same (source, arguments)
7. CompareValidator
A. Compare to a value or another control
1. IE the two entries for changing a password
B. Operator property can also be used to:
1. Compare entry = to a value
2. Compare entry <> and not equal to
C. Operator = DataTypeCheck just to make sure it’s the valid data type
1. Type = set to data type to check for.
2. The client side code procedure name has to be included in the ClientValidationFunction property of the control
8. ValidationSummary control
A. Place all error messages in one place…and use * next to control with error
B. Easy…replace all text properties (not error messages) with * for all validation controls
C. Insert the ValidationSummary control at the bottom
D. Error messages will appear when the page PostBack.
E. Set the DisplayMode to change looks
F. Set Visible to False…and ShowMessageBox…true…= popup

Monday, July 16, 2007

Events, Data Types, Procedures, Classes in ASP.NET

1. Events, Data Types, Procedures, Classes
2. Events
A. Simple concept 1.
1. ASP.Net programming = place server controls on a Web Form then code for their events. Big change from old ASP.
B. Simple concept 2.
1. Event handling takes place at the server…NOT the browser
2. Example…coding a command button click event triggers a postback so the server can deal with the event code.
a) If multiple events then they are stacked and processed on the server when a postback occurs. (Try: put Response.Write(“tag”) in three event procedures (textbox, checkbox, radio button) with only one having a postback)
3. Only a few controls automatically postback with the user.
a) Some controls require the AutoPostBack to be set for immediate response.
b) Use this with caution
C. Simple Concept 3
1. Round trips to server are expensive…keep it simple.
D. Simple Concept4
1. Each round trip triggers a Page_Load
2. If Not Page.IsPostBack then
a) Do this stuff once when the page loads the first time.
3. End If
3. How Events work
A. Double click on a control = open’s the editor and creates the default event stub
B. Unlike VB6 the event name is arbitrary….can be anything
1. What is important is the Handles clause btnClick.Click
a) Must match object name
2. Handles can support multi objects as long as they all share the same type of e parameter….
C. All Events have two parameters
1. sender is the object that generated the event
a) Use with multiple objects in the handles clause to determine which triggered this code
2. e holds all the event arguments…e.row, e.col, e.text etc etc….they are all buried in the e parameter in various properties
4. Common Button
A. Remember the command button will always trigger a postback
1. It creates an HTML submit button.
2. On the server the page Load event will fire
3. The button event will be handled
4. And the modified page will be returned
5. The ListBox
A. Made of item objects
1. listbox.Item.Add(“text”) adds an item
B. Selecting an Item triggers the SelectedIndexChanged event
1. Listbox.SelectedItem.Text = the item selected.
2. But does not trigger a postback
a) Must set the AutoPostBack=True
6. Radio Buttons
A. RadioButton…requires a “Group” name to group together
1. Can select only one from a group at a time.
B. RadioButtionList: Used with databinding to display a set of records as radio button list.
7. Radio Button raises CheckChanged event
A. Requires the autopostback like the ListBox
B. Work as a group set the groupname property
1. Group List is similar but does to require a groupname
C. But the CheckChanged event works independently on each button
1. You want the same code to run on both like a control array in VB
D. Modify the Handles clause on one CheckChanged event so it can handle the event for many objects.
1. …..handles rbtBlack.CheckedChanged, rbtWhite.CheckedChanged
2. Use “If sender” to determine which object triggered the code.
3. Note using the If sender Is operator (not =) because this is an object
E. Each PostBack = another Page_Load event
1. So: If Not Page.IsPostBack then….
a) Runs only code the first time
8. Data Types
A. Key points.
B. The Framework all share the same datatypes
1. Some of the old VB datatypes are different
a) Learn them as you go.
C. Option Explicit is turned on by default
1. Means you have to declare (Dim) a variable before you use it.
D. Option Strict is turned off but you SHOULD turn on before using it.
1. Means you have to explicit convert data types
2. Can NOT add strings (in VB you could)
3. To Turn on Option Strict : Project properties . Build
E. Can declare and initialize a variable at the same time
1. Dim intDemo as Integer = 100
9. Thoughts on Data Types
A. No Variants…(instead use object data type)
B. Currency is gone…use the decimal data type
C. Integers
1. Default is 32 bit: Most common form of non decimal type
a) Short is 16 bit
b) Long is 64 bit
D. Single & Doubles= Use with numbers with decimal point.
E. String = text
1. Char = 1 character
F. Date = Date and Time
G. Converting Strings
1. Use Object.ToString, CStr, CType
2. Note .ToString(“yyyy-MM-ddTHH:mm:ss”)
H. Use CType to convert between Data Types
1. Dim decDemo1 As Decimal = CType(200.23, Decimal)
2. CType(a,DataSet) …. Convert anything into anything
I. DirectCast(val,type)…faster but does not change data type… just declares it.
J. Or use CFuntions
1. Dim decDemo As Decimal = CDec(100.23)
10. Adding to self
For y = 1 To 10
x += y or
(x = x + y are the same thing.)
Read from right to left y is equal to x + self.
11. String.Format: Easy building and formatting of a string.
A. Used to create string blocks with embedded variables: Very cool
1. Instead of “string “ & data & “ string “ & data etc
B. strDemo=String.Format(“String block with {0} variables (1)”,”data in 0”,data in1)
C. Can format the values standard expressions such as with {0:C} = currency
12. Writing Procedures = reusable code: Easy
A. Concept…combine lines of codes under one name you can call when ever you need to run those lines.
B. Private Sub Name(parameters)
1. It will put in the End Sub
2. Parameters are passed as ByVal by default
C. Private Function name() as datatype
1. The value defined by RETURN is the result of the function
13. Creating Classes (encapsulating behavior)
A. Concept …. Combine (encapsulate) procedures under one name so you can create an instance of that class…and get all the procedures.
1. A class is a template or group of functions
B. Add a Class module to your project
C. Or create a class on a WebForm itself…
1. You create “additions” to the base class with your class
2. Go to the bottom on code and type Class name…end class will be inserted
D. Everything in .NET is based upon a base class
1. Check the first line of your web form
14. Creating properties
A. Public Property name as data type: Property User() As String
1. Get and sets will be inserted
2. Value (the set parameter) will be created
3. To create a readonly = Public ReadOnly Property
15. Public Function name() as data type = exposing a method
16. Instantiate your class (create an instance of the class)
A. Dim oClass as New ClassName … this is an Instance of ClassName
B. oClass.Method is the Instance.Method
1. Now you have access to all its properties and methods.
17. Using Public Shared: Do not have to Dim the object to use it.
A. Create the function as Public Shared
1. Public Shared Function ShareConnectString(…
B. To call it …. Class.Method name…this is called a Class Method
18. Shared Properties only work if the internal variable is also shared.
A. You will forget this and it will cost you a few hours of debugging.
19. Going to another page in code
A. Server.Transfer(“page”)
1. Works like a Goto in code.
2. Terminates execution of the current page and begins execution of a new page.
3. Does not require a round trip back to the browser
4. Note that the URL in the browser does not change.
B. Response.Redirect
1. Tells browser to Hyperlink to another URL
2. Can link to any location at any site.
3. No ‘html’ code prior to this statement
4. The URL is now the new page.

Saturday, July 14, 2007

ASP.NET and dotNet Framework XML Web Services

1. Using HTML to create Web sites.
A. All static. Requires Web Master to continually update pages
B. Very difficult to deal with databases
3. Using ASP: Active Server Pages
A. The Web server can run script locally and then return HTML on the fly
1. Good for working with databases
2. But script language was very limited
B. Old ASP = one file a jumble of HTML, server side and client side code.
1. ASP.Net can still use script but it goes in the HTML view.
4. Using ASP.NET and the dotNet Framework
A. Design (HTML) and code (VB) are separate files.
B. Web applications can be designed with a real programming language.
C. Can use any language you feel comfortable with.
5. Login Form from book: Page 102
A. Tips: When creating a new project
1. Delete the default Webform and add a new one with your name
2. Set the new form pagelayout properties to flow not grid
B. The .aspx file is just the layout information
C. Code is separate in the code-behind file .aspx.vb
1. Very nice: Can update your code without fooling with the layout…live.
D. When you trigger an event (like a button click)
1. The page does not change locally. It posts back to the server
2. The server responds by resending the page with requested changes.
a) ASP.NET takes care of re rendering the controls with your “entered” data in it….old days you had to recode all this..(so you just didn’t do it.)
3. NOTE this saves you hours of work compared to ASP.
E. Dim x,y as integer ‘works
F. Dim x as integer = 5 ‘called dim and initialize.
1. Handy but does not let you trap an error on this line.
6. ASP.NET
A. Technologies that make up ASP.NET
1. Web Forms: For User Interaction
a) Used to layout server controls
2. Server controls
a) Still supports HTML controls
3. Validation controls: Used to validate user input.
4. Web Services
a) For interaction with other programs.
B. All use the Code-Behind concepts
7. XML Web Services: No User Interface
A. A function that is called across Internet
B. Programmatically request data or action across the net.
1. And the remote side triggers and returns data.
2. As long as both sides agree on the SOAP method of packaging requests and responses then ASP Web Services
C. Always returns an XML string
D. Servers Publish or Expose and clients Consume Web Services
E. Easy concept:
1. You create Public functions
2. These are exposed to the Web with the tag
3. The compiler does the rest!
F. Support files automatically created.
1. .VS Diso = discovery file that lists the Web Services on the Web Site
2. .WSDL = Web service description language. Methods available and parameters
8. Web Forms: User Interface to hold controls
A. They are for server side only (the user never “sees” this form)
1. In runtime aspnet_isapi.dll will render the aspx page as HTML
B. Two files: .aspx & aspx.vb
1. .ASPX will be the web page the user will surf to.
a) .vb file will be used by the compiler to create the application DLL
b) .cs if using C
2. (.vb ) The Code behind always runs at the server
3. If you want client side script you have to put it in the HTML design view.
9. Web Form Controls:
A. Come in two flavors:
1. Server Controls (green triangle) found in Server Control Toolbox
a) controls that tell aspnet_isapi.dll to return themselves as HTML
2. HTML (like old ASP/HTML controls) and live on HTML controls toolbox
a) Standard HTML controls. No server side processing.
10. HTML Controls (old)
A. HTML controls are standard HTML controls
1. They are returned to the browser as is.
B. Used for compatibility with existing pages
C. Rare in VS.NET
11. Web Form Server Controls (note the green handle = Web Server Control)
A. Place holders = Little “code generators”…but you never see the code.
B. In HTML view: Note the ASP: tag in front of the name of the control
1. :tag that triggers IIS to call .NET to return standard HTML controls at run time but configured dynamically …. The way you want it at that moment.
C. During design they appear for your design benefit.
1. Best is to work in Flow page layout mode
D. Output is based upon the type of browser detected
1. Supports various DHTML as necessary
2. But you don’t have to worry about it.
E. Field Validator Controls
1. Java script code generator
2. Perform client side (no round trip) user validation
a) Takes the place of the client side Java script we had to write for ASP
b) Even if client does not support Java…server will validate.
12. How the Web forms work (key point…it all happens on the server!)
A. User requests an .aspx page…the associated DLL from bin folder is loaded and processed on the server
B. Key point… On the browser side this is a simple HTML post page.
C. Once the post on aspx is triggered the following happens on the server.
D. Init event fires (helps manage state) but you do not program here.
E. Load event is triggered: Important!
1. Very common. If you click on a button that triggers a “postback” the page must redisplays itself…this is a round trip to the server.
2. Although the event is triggered on the local browser (ie a click) the server has to process the event associated with the click…= PostBack
3. This may require you to check the Page.IsPostBack property to see if this is the first time through.
F. If it is a post back then all the change events that were batched up on the client are triggered
1. These batched events will trigger in random order…careful
G. If it is a post back…then the server raises the event that got triggered to force the postback
1. Some controls force a post back when you click on it. (buttons)
2. Other controls (like the listbox) must set AutoPostBack = True to force a post back on the click
13. How “IIS” Objects Work: Used to be the core of ASP programming
A. Response Object: Place data into the HTML stream as leaves the server
1. Used to force output (as if you were typing the page)
2. Response.Write(“this will be send to the browser”)
3. Response.Cookies to Create cookies
B. Request Object: Read data coming from the browser
1. Used to read information coming from the browser
a) Request.Cookies to read cookies.
2. Input fields or URL information
a) Request.Form and Request.QueryString
C. Session Object: User (session specific) variables stored on the server
1. In ASP we avoided these because they clogged the server
2. In ASP.NET they are managed by the Framework more efficiently
D. Application Object: Variables used by all users one application…
1. IE connection string
2. Better in ASP.Net than ASP
E. Server Object: Provides information about current state of server
1. Server.MapPath(“Hello.txt”) returns the exact path to that file on the current server.
2. Provides access to the SERVER_VARIABLES. (ip addresses etc)
F. Global.asax: Like the global.asa in ASP but more events
1. Holds events that get triggered site wide
2. Application_Start and _End (when IIS starts and ends)
3. Session_Start and _End (when a user opens their first asp page)
4. ASP.NET adds about a 14 other Application_ events
a) Used to trigger events as ASP.NET processes Web Forms pages
14. Custom Controls and User Controls
A. Custom controls are objects like the ones in your toolbox
1. We will not be creating these in this class
B. User Controls are similar to #Include files
1. You create a page of code and save it.
2. Then drag the “Control” onto a page and it acts as if you typed it there
3. Great for standardized headers, footers and library code.
C. Easy to create
1. Create a new form and remove all the code
2. Insert just the stuff you want to appear as an include file
3. Change the extension from .aspx to .ascx
4. Drag it on to any other web form…
D. You use these extensively in your Final Project

Wednesday, July 11, 2007

To Know .Net is to know the .NET Framework

1. To Know .Net is to know the .NET Framework
Class Libraries = Objects called in all languages
A. Think of boxes with functions in them
B. {} = a namespace, just a box.
2. What is a class?
A. Think of a small box with a name
1. You create a instance of that name and you get all the cool stuff in the box
B. There are thousands of classes.
3. What is a Namespace: A box with other namespaces &/or classes in it.
A. Easy concept. Big box with smaller boxes with smaller boxes.
B. Each bigger box is a namespace.
4. Namespace rules
A. To use a namespace it must be referenced
1. In Solution Explorer note the Reference heading
B. Next you must refer to the specific object by it’s full name
1. Dim dr as new System.Data.SqlClient.SqlDataReader
2. That’s the System namespace with the Data namespace etc etc
C. But you can use the imports statement at the top of page as a short cut
1. Imports System.Data.SqlClient
2. ….
3. Dim dr as new SqlDataReader
D. VB .NET projects has some implicit imports (built in imports)
1. Right click on a project . properties . imports.
5. Memory Management
A. In .NET =nothing means you don’t need it but it will not kill it until the Garbage collector comes along
1. Non Deterministic finalization
2. Marks for Garbage of collection
B. Bottom line. .NET will clean up your objects…BUT
1. ds.dispose (dispose method) is a nice touch.
6. System.Data Namespace work with data
A. Data access is built into the .NET framework (referred to ADO.Net)
B. System.Data.SQLClient = manage connections to SQL server 7+
1. or System.Data.SQLClient = manage connections to other OLE DB providers (old way outside the CLR managed environment)
2. .DataAdapter= “plug into the database”
C. System.Data = manage data in memory (ie disconnected)
1. .DataSet = in memory database (XML) with one or more datatables
2. (DataReader…one time firehose)
a) .DataView = sort and filter a datatable
b) .DataTable = collection of DataRows
D. Passing thought…DataSet is also our XML parsing tool.
E. See Data Example
7. System.Web.Services: B to B (application to application)
A. Old Days…to execute calls in other apps = ActiveX & DCOM
1. But DCOM is binary. Doesn’t make it through firewalls
a) Supported only on Windows platform
B. New Days … Expose “service” as XML Web Service
1. Call & Response in XML text…all platforms
C. Web Services can be consumed (cool term) by
1. Windows app, Web app, cell phone,
D. File . New . Web Service
E. The key to a Web Service is Public Function …
F. This function can be called from any “consumer”.
1. And will return the results in XML format that any consumer can understand
G. Build . Build solution creates the .DLL

Why .NET Framework and Visual Studio

1. Getting More Help!
A. On Line Help in VS is good! Use it!
B. Our on line tutor:sledwith@saddleback.edu
C. http://www.dotnetjunkies.com/search.aspx
2. What is the .NET Framework
A. Common Language Runtime (CLR)
1. Previous: All languages had their own “runtime engine”
a) VBrun…. MSVCRT (C++) etc
2. Now: All .NET languages use the same runtime engine.
B. .Net Framework Classes
1. Previous: Each language has it’s own “API” or objects with their own capabilities…so everyone thought they were better.
2. Now: All .NET languages share the same “Class Libraries” or objects
a) Think boxes of code that you can open and use in any language.
C. Why .NET Framework
1. Use any language, any device, any location…all work together
2. Plumbing is already done: No more “registry code” or “memory management” code
3. Takes care of all the XML and SOAP for you.
4. Better optimized so FASTER!
D. Path from your code to a running application?
1. VS uses the CLR to create “managed code” or code created by/for the .NET Framework.
a) MSIL: Microsoft Intermediate Language.
b) This goes in the EXE or DLL
(1) Just text; can be edited…
2. The Just In Time Complier (JIT) in the .NET Framework
a) Translates the MSIL into something your processor / OS can handle.
3. New: Data is stored locally in a DataSet as XML (with schema) and is disconnected for the data source. Think Web…local database!
3. What is Visual Studio.NET
A. The .NET framework (classes and CLR) are all free.
1. Don’t have a life? Program to .NET with Notepad. Very tough but doable.
B. Visual Studio.NET provides a developer friendly front end to .NET
C. What languages: Dozens but 5 big ones
1. VB.NET (most common)
2. C++.NET (.NET is written in this)
3. C#.NET (user friendly C++)
a) No pointers, no memory management, has string data type
4. J++.NET (Java like)
5. J#.NET (just came out..user friendly J++)
6. Bottom Line…all use the Framework = Intermediate Format.
D. What languages are NOT in .NET
1. VB script or Java script…no more “scripting languages”
a) But makes a find ASP script ‘editor’
2. ASP.NET…this is not a language..
a) It’s a combination of technologies (including one of the languages above) to create server side web applications.
E. Common Data Types
1. All share same “types” but different languages user different names
2. See chart in the book.
3. String is a different animal…it is not a simple value type…it is an object
4. There is a date data type….
F. What types of apps can you create?
G. Windows Applications: (Run locally)
1. Windows Forms: Classic windows applications but much more portable.
2. Windows Services: (NT, 2K and XP) run in the background all the time.
a) No GUI, think scheduler service.
H. Web Applications: Run on Web Server
1. Web Application (interacts with User: Think Amazon.com)
a) ASP.Net = provides capabilities of .Framework to Web based applications
(1) ASP scripting is still doable but not ‘managed’
b) ASP.Net Web Forms (GUI option for Web app)
(1) Like Windows forms but for the Web
(2) Replaces the HTML form controls of ASP
(3) All server side! Not browser specific.
I. Web Services (interacts with another program.)
1. Think Credit Card Authorization
J. Class Libraries
1. DLL’s with functions you can call in other applications
4. Versions: Visual Studio .NET 2003
A. Develop for mobile devices
B. Uses .NET Framework 1.1 (security, performance, enhancements)
C. J#
D. Improved Debugger
E. New IDE provides improved start-up time, performance, and reliability
F. New managed providers offer easy access to Oracle 7i, Oracle 8i, and ODBC data sources
G. General clean up from the introductory version.
5. Installation: Easy but long!
A. Windows 2K (pro or server) XP, 2003
1. If 2K Pro or XP then install IIS first.
B. It will ask for the component update CD first
C. Then choose which parts to install
1. VB & Crystal for this class
6. Optional: Creating an IIS (Web Server) Virtual Directory for your apps
A. Default…they end up in wwwroot of localhost
B. Create a folder to hold your projects.
1. Example: dotNetProjects
C. Right click on My Computer . Manage . Services . Internet Information Services .Drill down to Default Web Site . Right click . New
D. Virtual Directory . Name (short!) . Location is the folder you created.
E. Accept defaults
7. *Configuration
A. Tools .Options . Text Editor . Basic .
1. Uncheck hide advanced members
2. Uncheck Word Wrap
3. Check line numbers (helps with debugging)
B. Tools. Options . Environment . Projects & Solutions…
1. IF you created a virtual folder to hold your web applications you can default to it here.
C. Note Projects . Web Settings: Location of VSWebCache
1. You can move this but in any case you may have to clear this folder out.
8. Making Flow Layout the default choice.
A. C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\WebApplication\Templates\1033
1. and
B. C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\WebForm\Templates\1033
1. Always make a backup before changing!
C. Change WebForm.aspx
1.
2. to just (take out the MS_......)
9. To make Option Strict the default. (Pain; but you only have to do it once!)
A. Start . Search . Files or Folders
B. Search for: *.vbproj
C. Look in: C:\Program Files\Microsoft Visual Studio .NET\Vb7\VBWizards
D. Edit these files and add the OptionStrict = “on” such as



OptionStrict = "on"
E. …….more settings.
10. Solutions, Projects and general file layout.
A. Projects are the Web folders that contain your web project
1. One language per Project
2. Project file is the key.
B. Solution is just a grouping of projects…for organizational purposes
1. Each project must be in a solution.
2. Common to have one solution and one project same name.
11. Creating a new project (File . New or Ctrl N)
A. Left: we will be working with VB projects
B. Right are the project types
1. Windows application are the classic VB6 apps
2. ASP.NET Web Applications are what we will be doing
C. Note that ASP.Net will ask you for a server and project folder (name)
1. The server you choose must have .NET framework on it.
2. Folder you create becomes a virtual directory (folder) on the Web Server
3. The name of the project is the Folder Name.
D. After creating the Web app .NET connects to the web server and builds the directory.
1. Loads it with appropriate files
12. First Steps with new project (if defaults are not set)
A. Project Properties . Build . Option Strict On
B. Project Properties . Designer Defaults . Page Layout Flow
13. How to rename a form: 3 steps
A. Right click on form and rename
B. Open the code window and change the Public Class newname
C. Open the HTML and check first line “Codebehind="newname….”
14. Adding a Web page…easy. Right click on Project . Add . Web Form
15. The IDE (Intergraded Development Environment)
A. Two types of windows: Tool Windows and Document Windows (you type)
1. Tool windows come with VS, Document windows you create
a) Tool Windows have push pins
2. Dock with double click vs dragging the border
16. Working with Tool Windows….lots
A. Autohide or not….
1. Push pin to side…autohide on…
a) pin pointing down…window is pinned down = autohide off
B. If autohide off then window can be docked or float
C. If float then you can drag them onto a second monitor.
D. If dockable…double click on title bar to undock
1. Now watch as you click and drag on the title bar
2. Slowly and you can see the grey outline.
a) Can dock in at least three formats…top, bottom and tabbed
17. Toolbox: Ctrl Alt X (for box)
A. Lots of stuff here…note the clipboard ring (last 20 items on the clipboard)
B. Not in alpha order. Order of most commonly used
C. After placing a tool on form
1. That green icon in the left top corner indicates a server-side control
a) (1)Control that is generated on the server and accessible in server-side code.
b) Server-side control don’t really exists. They are IDE place holders for the HTML control that the server will create on the fly.
2. Web Controls are ALWAYS server-side controls.
a) HTML controls CAN be server side if you add an ID attribute and the runat="server" attribute.
3. Client side controls are usually pure HTML.
18. Solution Explorer: Alt Ctrl L (for ‘List’)
A. List of files you can edit in your project
B. Buttons at top
1. First two switch between design and code windows
a) Hint. F7 and Shift F7 (thank heaven for code window)
2. 5th window will show all files.
C. CAREFUL
1. Right click on Solution is different than right click on project
2. Both have own (but different) ADD and Properties
19. Server Explorer: Ctrl Alt S (for server)….very cool
A. Provides access to ‘services’ running on your box or other server
B. Most obvious is SQL data services
C. But also have access to performance monitor, event viewer etc.
20. Properties Page (F4)
A. Properties for the current object
B. Note that the properties page (right click) is different from F4 properties
C. Tip. Changing properties is just “editing” the HTML view.
1. Both do the same thing.
21. Task List (Ctrl Alt K): More than a ToDo list
A. Includes build errors
B. Double click on error in task list and it takes you to the error.
22. Help: Is Excellent (F1) but requires entire MSDN (lots of disk space)
A. Context Sensitive: F1 while on the item to get help on.
23. Editing Window
A. A Web Page is actually made of two pages
1. .apsx is the Design page…what you see
a) This has two views: Design and HTML (note buttons at bottom)
2. .aspx.vb is the “code behind” page
B. Switching: Double click on Design page to get to code
1. Or use buttons at the top of the properties.
2. F7 and Shift F7
C. Change the Edit Window from Grid to Flow layout
1. Document Properties (F4). PageLayout.
24. Using the Text Editor
A. Hint: Check out Edit . Advanced menu
1. Format is handy in HTML view
B. IntelliSense: As you type it gives hints
1. Ctrl J to force it
2. Ctrl Spacebar to autocomplete.
a) Space to complete and leave a space.
b) Tab complete and not space
c) Enter complete and new line
C. Can Split the window with the splitter bar
D. Use Find (Ctrl + F) and Replace (Ctrl + H)
1. But only currently opened files
a) Note find box in tool bar
E. Edit . Find & Replace: Find in Files
1. All files!
F. Auto Indent
1. Auto lines up code no matter where you start
2. Auto indents Ifs and loops
a) Highlight your un indented code…then press tab
G. Word Wrap (use with caution)
1. Ctrl R + Ctrl R
H. Incremental (or search as you type) search (Ctrl Alt I)
1. Note the bino icon.
2. And start typing…it will find the next search
I. Bookmark code (Ctrl K, K) turquoise mark
1. Ctrl K , N to go to the next mark
J. Commenting code: (Block comment from the text editor tool bar)
1. ‘ is used for a comment.
2. Note toolbar
K. Full Screen: Alt Shift (All Stuff) Enter
L. Ctrl Tab between windows or tabs
25. Build & Run your Web Forms: Set START PAGE!
A. F5: With debugging (slower but lots of information):
1. Right click in solution explorer on a page to set the start page
a) Hint…set a break point to pause the debugger
2. F5 to start the debugger
3. Shift F5 or close the browser to stop the debugger
B. Without Debug but in a browser (ie real life)
1. Set a start page
2. Ctrl F5
C. Without Debug but within VS running as if in browser (FAST!)
1. Right click on solution explorer page: Build and Browse
2. If nothing has changed you can just select Browse
a) If something has changed Browse will ask you to save changes
(1) Same as Build and Browse
26. ASP.NET files: (you can open in notepad)
1. .sln: note the location of the web site
2. vbproj.webinfo: note the location of the web site.
a) This file can be deleted between runs
3. You can delete the .suo between runs

ASP.NET DropBox Calendar control

1. Create a New Web Project Assignment10
A. Add Web Page DropBox.aspx
B.
C. Use Header user control from the previous assignment. Format as shown.
1. Menu is not required.
D. Select a folder with at least 5 files with at least 3 having .DOC extension.
E. Bind a radiobuttonList as textfield=Name and the valuefield=path
F. Clicking on a radio button will download the selected file
1. Response.redirect to the path.
G. You will modify 3 times and print results for each of the following…
1. Bind directly to the DirectoryInfo object. No specified order.
2. Bind to a dataview sorted in descending Name order
3. Bind to a dataview sorted ascending, filtered so only .DOC’s are listed.
H. Print each showing the Listing and Download works.
1. Clearly label as each printout as one the above 3
I. Sample code to get you started:
1. Import System.IO
Dim DirInfo As New DirectoryInfo("c:\data\Classes\dotNET\Notes")
Dim FileItem As FileInfo
Dim dsFiles As New DataSet()
Dim dr As DataRow
Dim dv As DataView
dsFiles.Tables.Add("FileList")
dsFiles.Tables("FileList").Columns.Add("Path", Type.GetType("System.String"))
dsFiles.Tables("FileList").Columns.Add("Name", Type.GetType("System.String"))
For Each FileItem In DirInfo.GetFiles
dr = dsFiles.Tables("FileList").NewRow
dr("Name") = FileItem.Name
dr("Path") = FileItem.FullName
dsFiles.Tables("FileList").Rows.Add(dr)
Next
dv = dsFiles.Tables("FileList").DefaultView
dv.Sort = "Name ASC"
With rbtFilesList
.DataSource = dv
.DataTextField = "Name"
.DataValueField = "Path"
.DataBind()
End With
To redirect and open the file.
Private Sub rbtFilesList_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rbtFilesList.SelectedIndexChanged
Response.Redirect(rbtFiles.SelectedItem.Value)
End Sub
2. Add Web Page Calendar.aspx
A. Use two raidobuttionlist server controls and NOT visible calendar
1. Calendar only displays when a employee is selected
B. Bind one raidobuttionlist to the “first letter” of the employee’s last name
1. Use distinct and left functions in your SQL statement
2. Result is a list of radio buttons, one letter each.
C. Upon selecting a letter; bind the other radio button list to all employees
with last name that begins with the letter.
D. Upon selecting an employee,
1. Make the calendar visible.
2. Display that employee’s birthdate in the calendar control
E. Upon selecting a different date make link button “Update” visible
F. Selecting Update will change the birthdate to the selected date.
G. Hide both the Update and calendar when a different letter is selected.
H.
I. Screen print to show it works
1. Select an employee and show the date gets updated.
2. And code.
3. Add WebForm SurfShots
A. Add AdRotator
B. Add images folder
C. Using images.goggle.com save 5 surfing pictures to the images folder.
D. Modify the Ads xml file from thebook to load the pictures
1. Replace data as necessary
2. Make one “ad” impressions = 5
3. Rest is up to you.
E. Create a ClickThrough.aspx page that displays the name of the image.
F. Print…two photo pages and associated ClickThrough link page
G. And Print the Ads.xml page!
4. Add WebPage State.aspx
A. Configure as follows
B.
C. On Test State Link button click
1. Name is stored in Session variable
2. Age is stored in 30 day cookie
3. Hair is passed in the QueryString in the response.redirect
4. Response.Redirect to StateTest.aspx
D. On TestState.aspx Display the values you stored.
5. Print your cookie with WordPad
A. C:\Documents and Settings\username\Local Settings\Temporary Internet
Files
6. Set View State Link Button
A. Set three StateView variables called School, Class, Grade.
Page 3

ASP.NET Crystal Report

1. Create the Crystal Report Page
A. You may need to modify your code to deal with a password.
B. Print showing filtered selection from drop down list.
2. Create the following Crystal Report using the Crystal Viewer:
A. Invoices View grouped on Salesperson: Total on Extended Price
B. Executive Leading break format (wizard)
C.
D. Tips: use the wizard to format most of the report.
1. Note the date, currency and heading
2. Place the initialization code in Page_Init
E. Some helpful code
Public Sub InitCRV()
'**called from page_init in top hidden region
Dim crReport As New Sales2
crReport.SetDatabaseLogon("sa", "password")
With crViewer
.ReportSource = crReport
.DisplayGroupTree = False
End With
End Sub
3. Create the following Crystal Report by writing to a PDF file
A. Add a PDFCache folder to your project and set permission ASPNET =
Modify
B. Add routine to clear the PDFCache of reports over 1 day old
Page 1
C. Modify drop down list to include all sales people with the first item being
1. “”
D. Modify the click event to ensure that a salesperson is selected
E. Clearing check box will suppress detail.
F. Extra Credit: Show only the report
1. Suppress PDF Viewer Interface including Toolbars and tabs (as much as
possible)
2. Suppress the browser interface
G.
H. 1.
A. Print the new Main Page after both new user controls have been added
B. Print the DropDownList UserControl
1. Highlight the Event Declaration(s) and where you raise the event(s) in
your code…
Page 2
C. Print the code and results of your test page
5. Add a User Control named Header.asc
A. 1.
C. Expose the following properties / labels in the code behind.
1. Title (label), Home (hyperlink), Path (label), User (label),
Public WriteOnly Property Title() As String
Set(ByVal Value As String)
lblTitle.Text = Value
End Set
End Property
Public WriteOnly Property Path() As String
Set(ByVal Value As String)
lblPath.Text = Value
End Set
End Property
Public WriteOnly Property User() As String
Set(ByVal Value As String)
lblUser.Text = Value

ASP.NET ItemStyle & AlternatingItemStyle

Data Repeater
A. Printouts: HTML View and Code View for both Category and CatetoryDetails page.
B. Printouts showing both working
A. Print Code, HTML, Template Editor
B. Print Running both Normal and Edit.
3. New Project Chap19
A. Add a new Web Page Products
C. Bind to Products Table as Shown
1. Note formatting on Price.


Unlike shown… use a table to make text boxes line up.
4.
5. Save = update or insert based upon “Add Mode”
A. Save and delete use CommandArgument to hold ProductID
6. Add
7.
A. Note:
1. Use2. Photos come from images.google.com
a) Right click on image and save in an images folder
b) Consider using ProductID or ProductName as image name.
c) Use either the PhotoURL derived column in the SQL statement as shown in the book OR
d) Build the path directly into the HTML.
B. Edit and Add New as shown above
2. Cut and paste both the link button and code.
C. Print:
1. Code, HTML, Screen prints of display and edit mode.
2. Show saved changes

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

ASP.NET how you read the data sent in the Query String

A. Add Existing Item and use the Data.aspx from Assignment 4
B. Place a label called lblError below the listbox.
2. Edit the connect string and change add x to the end of the password (to make it fail).
A. Check the web.config and confirm that customErrors mode="RemoteOnly"
B. Run and Print default error page
3. Edit the Web.Config file
A. Change customErrors mode="On" and run again.
B. Print the default generic error message
4. Create a new generic error message page called genericerror.htm
A. Include a message that says “Sorry we are down, check back later”
B. Add an appropriate image (check images.google.com)
1. Copy to images folder then drag onto page.
C. Modify the web config to show this page when mode="On".
1. Print web config
D. Trigger error to test and print the results
5. In the button click event….
A. Wrap up the data access code in a Try …Catch block
1. Display the expection.message in lblError
2. Exit sub within the Catch
B. Place the following code in the Finally block
da.Dispose()
ds.Dispose()
Print your code
C. Screen print showing results of the message in lblError
6. Remove the Finally clause and dispose methods
7. Create a Private Sub ByteError as follows
Dim x As Byte
x = 230
x = x + x

A. Call ByteError from the button click event right after the Try statement
B. Print the resulting message as displayed in lblError.
1. The error should have been passed back to the calling sub with the error handling code.

8. Add a “Catch ex as …..” to the Try block ………
A. Capture the specific System.OverflowException error
B. Set the label to “Bad Math” and exit
C. Print
9. Add a new class Called MyWebBase to override the Web Page Class
A. Inherit the System Web page base class
B. Override the On Error event and PageLoad as shown
1. There is considerable work here so plan accordingly.
C. Create a new MyErrPage.aspx that will display information you send it about the error
1. Pass the error information in the QueryString as show below.
2. Error Message, Name of page, date/time
D. See attached for my code to do this
10. Modify Error trap as follows:
A. On the line prior to lblError.text = … in the trap insert
1. Throw ex
2. This will propagate the error to the base class
B. Print all code and running example to show it works
11. FROM BOOK…Do Chapter 13
A. Print code and completed Products page.
12. Add Existing Customers Page from Assignment 4
13. Create a Class Called DataSQL with Public Shared Function CS() As String
A. Replace all connect strings with references to this function
14. Add Freight column to the grid
15. Add a label that says “Sum of Freight for current customer is “
A. Update this label when customer changes.
1. Use cm.ExecuteScalar
16. Add a button “Add 5 cents” (example not shown)
A. Create a sub that updates the current customer’s freight by adding .05
1. strSQL = "Update Orders set Freight = Freight + .05 where CustomerID = '" & ddlCustomers.SelectedItem.Value & "'"
B. Call this sub from the button click
C. Then reload the grid and update the Sum Label.
17. Implement Error trapping of your choice for all data access

18. Sample Code for MyBase
Imports System.Diagnostics
Public Class WebBase
Inherits System.Web.UI.Page
Private mstrPageName As String

Protected Overrides Sub OnError(ByVal e As System.EventArgs)
Dim exp As System.Exception = Server.GetLastError
Dim strCurErr As String
Dim dteCurDate As DateTime


strCurErr = String.Format("Error={0}&Page={1}&Time={2}", Server.UrlEncode(exp.Message), Server.UrlEncode(mstrPageName), Server.UrlEncode(dteCurDate.Now.ToString))

Response.Redirect("ErrorPage.aspx?" & strCurErr)
End Sub

Sub SetPageName()
If mstrPageName = "" Then
mstrPageName = Replace(Page.ToString, "ASP.", "")
mstrPageName = Replace(mstrPageName, "_aspx", ".aspx")
End If
End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Call SetPageName()
MyBase.OnLoad(e)
End Sub
End Class


This is how you read the data sent in the Query String
ErrorPage.aspx
txtError.Text = Request.QueryString("Error")
ditto for other two params

ASP.NET Data Adapter and Reader

A. Place two buttons on the form labeled “Data Adapter” and “Data Reader”
B. Place a listbox on the form
C. On the click of the Data Adaper - fill the list box with the Company Names
from the Northwind customers table
1. Do NOT use data binding to do this…Must use a loop
D. On the click of the Data Reader - fill the list box with the Company Names
from the Northwind customers table
1. Do NOT use data binding to do this…Must use a loop
E. Print results and code.
F. Highlight the loops you create.
3. Add a page called Customers
A. Place a drop down list (customers) and a grid (orders)
B. Populate the drop down list with all the Company names in the Customers
table
C. On selecting a different customer populate the grid with the orders for that
customer displaying the following fields
1. OrderID, OrderDate, ShippedDate
2. Sort the list by OrderDate
3. Format the dates
D. Extra Credit
1. Include Employee Name who made the order.
E. Print the running page with three examples of different customers
F. Print code.
4. Add Players Web Page
A. Manually create a players table and add to a data set as follows (see help
Data Table Class… all the code is right there.)
1. PlayerID = Autoincrement field, seed and start values = 1
2. PlayerName = string
3. HireDate = date
4. Rank = Int
B. Add at least three rows.. Each with different data
C. Bind to a grid and display.
5. Format the HireDate on the gird but can not change the datatype of the
column in the dataset.

ASP.NET Events Function FormatDateTime

A. Add a Web Form called Events
B. Place a button and label.
1. Code the button click event to set the label to “Hello World”.
2. Change the name of the button event procedure but not the handles clause.
3. Run again to prove it still works
4. Screen print
C. Place a dropdown list on the form
1. Populate the list with 10 names of stores from a sub procedure called from Page_Load:
a) Use Dim lstStores() = {x,x,x} followed with datasource,databind
b) This should run once …not on postback
2. Code the appropriate list event so that when an item is selected on the list the label says “I shop at “….. store that was selected
a) Run this a number of times….the list should stay the same…not grow
3. Screen Print it works
D. Place three radio buttons on the form
1. Label each with a different color, rbtRed, rbtGreen, rbtBlue
a) Assign a group name “Colors”
2. In a one event procedure code to set the label to “You clicked on “ color selected.
E. Turn Option Strict On
1. Add a button btnStrict
2. In the click event set the btnStrict.Text = 21
F. Add another Button: Text = Show Me The Date
2. Use at least two methods to do this
a) Hint… Format and FormatDateTime
3. Add a Class module called TaxClass
A. Create a property call TaxRate that accepts a value of type single
1. Assign it to a private internal working variable msngTaxRate.
B. Add a Function called CalcTax
1. That accepts a value called Amount, type single, returns a single
2. In the function calculate the tax on the Amount based upon the TaxRate
C. On the Events form place a button labeled CalcTax
1. On the Click event create an instanced of the class
2. Set the tax rate to .0775
3. Call the CalcTax method passing 10,000.00
4. Display the amount of tax in the Text property of the button.
5. Format as currency (you can not concatenate the $)
4. In TaxClass add a Shared Public Function called ShowMeTheMoney
A. Accepts a String (Name) and Double (Amount) and returns a string
1. Return “name made amount this month” and amount must be formatted with $ using the String.Format function.
B. On Events Form add a button with Text = Show Me The Money?
1. In the click event, in one line of code, change the text of the button to the string created in the ShowMeTheMoney function in the TaxClass.
2. The Amount should be formatted with $ and commas.
5. Screen running prints to prove it works and print
A. Be sure to print the class module code.
6. Add a link button called lnkDelete
A. Place code in your page initialize to add the onClick javascript confirm message box to the button.
1. btnDelete.Attributes.Add("onClick", "return confirm(' Click OK to Confirm Delete ')")
B. If the user clicks OK then set button label to “You Deleted This Item.”
C. File . Print all code.
7. Add a new Web Form called Validation
A. Create a data input form in a 2 column table with the following labels and text boxes
1. Full name: Input required
2. Address: Input required…BUT default text is “Enter Address Here”
3. Start Date: Input Required AND
a) Must be older than 1 and less than 30 years ago relative to today.
b) Place correct code in Page_Load and PRINT out this code
c) (this is coved in the book)
4. End Date: Any proper format date. (Hints; compare & operator)
5. Telephone: Input Required & Proper Format
6. Submit Button
B. Response.Write a thank you in Page Load if the postback works
C. Print once showing it all works
D. Modify by changing “in line” messages to * and inserting a summary control with all the error messages.
E. Print showing the new error messages at the bottom.

ASP.NET Response.Redirect Server.Transfer link demo

1. Add a WebForm called MyTable
A. In Project . Properties . Build make sure Option Strict = On
1. Change Designer Defaults . Page Layout to flow
2. Note you will make these changes on every form.
a) See first week notes to set global defaults.
B. Using the HTML view create the table shown below
C. Note: First date is strong, second date is bold
1. Bill Smith is emphazie and Mike White is italics
2. Set Table Cell Padding to 10 and check your Design View
3. Set Table Cell spacing to 10 and Check your Design View
4. The My Cool Table is centered across all columns
5. Hours are right aligned.
D. Write or Type a short explanation of the difference between the cell padding and spacing.
1. I will be looking for this explanation when I grade.
2.
3. From the Book: Pages 102-106, Pages 124-126
A. Screen prints of running application and print code.
4. Add a WebForm called PostBackDemo
A. In Project . Properties . Build make sure Option Strict = On
1. Change Designer Defaults . Page Layout to flow
2. Note you will make these changes on every project.
B. Add a command button (btnSum, text=0) and next to it:
C. Add a drop down list (ddlNames)
5. Code as follows
A. In PageLoad add 3 names to the list
With ddlNames
.Items.Add("Larry")
…..
B. In button click event. Increment the button . text by 1 each time it is clicked.
1. Hint. Convert to Int, Add, then convert back to string.
C. Run and click on button 4 times…so it counts to 4
D. Screen print drop down list with repeating names (
6. Modify as follows
A. Add an “If NOT Page.IsPostback then…. To page load around the ddlNames code.
B. Run and click on button 4 times and show screen print the ddlNames with only 3 names.
7. In Global.asax
A. In session_start initialize a session variable called SessionMapPath = Server.MapPath(“”)
B. Add a label under the sum button on the above page to display this variable.
C. Run, screen print and circle the MapPath.
8. Add a new Web Form Called LinkDemo
A. Add a label called lblCurrentSystemUser
1. = System.Environment.UserName (should be ASPNET)
9. Place two links on PostBackDemo to LinkDemo
A. btnLinkDemo is a link button coded with:
1. Response.Redirect to LinkDemo ,
a) Screen print and circle the URL
2. Server.Transfer to LinkDemo
a) Screen print the URL and explain the difference
B. hypLinkDemo is a simple hyperlink to LinkDemo
1. Not code… just properties.

Tuesday, July 10, 2007

Create ASP.NET WebService Project WebServiceDemo

  1. Draw a .NET flow chart / diagram showing the relationship between
    1. The program languages that come with VS.NET
    2. The .NET Class Libraries
    3. The CLR
    4. MSIL
    5. JIT
    B. On that diagram explain what each part does
  2. Create a new Project Called Assignment01
    A. Create a new WebForm called HelloWorld
    B. Screen print document property page changing to flow layout.
    C. Place a button (btnHello) and a label on the form
    D. When you click on the button the label displays “Hello World on (today’s date)”
    1. Date.Now.ToString("d")
    2. Find two additional formats for the date/time.
    E. Screen print code
    F. Screen print running results
  3. Screen print: Set the IDE as follows
    A. Toolbox and Solution Explorer to Autohide (pin side) with tabs
    B. Properties to Autohide (pin down) off
    C. Code behind with intellisense for Page.
    D. HTML view
  4. Create a new WebForm called Data (tip use the book to help with this)
    A. Use SqlDataAdapter, Dataset and GetXML
    B. Fill a textbox with XML with ProductID, ProductName from Products in Northwind database
    C. Tips: Textmode = multiline

    Dim ds As System.Data.DataSet
    Dim da As System.Data.SqlClient.SqlDataAdapter
    Dim strCon As String = "Server=surf7\VSdotNet;Database=Northwind;uid=sa;pwd=password"

    Dim strSQL As String = "Select ProductID, ProductName from Products"

    da = New System.Data.SqlClient.SqlDataAdapter(strSQL, strCon)
    ds = New System.Data.DataSet()
    da.Fill(ds)

    txtXML.Text = ds.GetXml
  5. Create a new WebService Project called WebServiceDemo
    A. Create a .asmx page called Service1
    B. Expose a WebMethod Function called Hello that accepts one parameter called Name
    1. Public Function Hello(ByVal Name As String) As String
    C. It will return the string Hello ‘name’ where name is the value that is passed.
    D. Screen print Code
    E. Screen print the results from the browser test.