Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic.NET Programming March 3, 2004. Agenda Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team)

Similar presentations


Presentation on theme: "Visual Basic.NET Programming March 3, 2004. Agenda Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team)"— Presentation transcript:

1 Visual Basic.NET Programming March 3, 2004

2 Agenda Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team)

3 Questions All homework homework due by Friday. Web Site will remain available for awhile, if not, contact me, I'll have the material. a tip... use the Microsoft Web Site Advanced Search to look up errors. I think it works half of the time.

4

5 Cookies

6 Cookies are a way to save information on the client machine between web page requests. A cookie is a name/value pair that the browser saves on behalf of the application. Cookies are keyed to the domain of the application. When a browser requests a page it automatically transmits the cookies that belong to that domain as part of the request. The application then reads the cookies and takes appropriate action.

7 Cookies Cookies are generally used in two ways. 1.To save some sort of user identifying information about the user, so that when the returns to a given site, the application knows who the user is. 2.The other is to save information indicating the application's state between web page requests within a single session. Although any information can be saved in a cookie, best practice is to use some sort of key to look up the actual information of the server.

8 Cookies Cookies are created by adding items to the Cookies collection of the ASP.NET Response object (available through the Response property of the Page Class). Example Dim cookie as HttpCookie cookie = New HttpCookie("MyCookie","MyCookieValue") Response.Cookies.Add(cookie)

9 Cookies Cookies are read from the Cookies collection of the ASP.NET Request object (available through the Request property of the Page Class). Example Dim cookie as HttpCookie cookie = Request.Cookies("MyCookie") Label1.Text = cookie.Value

10 HttpCookie Properties Domain – the domain associated with the cookie (string). Expires – date and time the cookie expires (datetime). HasKeys – whether the cookie as subkeys (boolean). Item – old ASP way of accessing subkeys, indexed by subkey name. Name – the name of the cookie (string). Path – the path associated with the cookie (string). Secure – does the cookies require a secure transmission (boolean). Value – the value of the cookie (string). Values – if the cookie as subkeys, Values represents an instance of a NameValuesCollection.

11

12 Topics Covered in the Visual Basic.NET Programming Course

13 Console Application Command Window Console Application

14 Windows Form Class Input Screen Windows Form Application

15 Constructors Fields Get Set Properties Methods Windows Form Class Class Input Screen Windows Form with Class DLL

16 Database Constructors Fields Get Set Properties Methods Windows Form Class Class Input Screen Windows Form, Class DLL, and ADO

17 WebForm Class Browser (IE6) WebForm Application Code Behind File

18 Database Constructors Fields Get Set Properties Methods WebForm Class Class Browser (IE6) WebForm, Class DLL, and ADO Code Behind File

19 Database Constructors Fields Get Set Properties Methods WebForm Class Class Browser (IE6) Web Services using localhost Code Behind File SOAP

20 Database Constructors Fields Get Set Properties Methods WebForm Class Class Browser (IE6) Web Services using Remote Host Code Behind File ClientServer SOAP

21 Web Form Client Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.text = "" Try Dim obj As New Service1 Dim ds As New DataSet Dim str As String = "Select * from NameAddress" ds = obj.ServiceGetDataSet(str) DataGrid1.DataSource = ds DataGrid1.DataBind() Catch ex As Exception Label1.text = ex.Message End Try End Sub

22 Web Service _ Public Function ServiceGetDataSet(ByVal SQLStmt As String) As DataSet Try Dim obj As New CDatabase Dim ds As New DataSet obj.SQLString = SQLStmt If obj.GetDataSet(ds) Then Return ds End If Catch ex As Exception Dim se As New SoapException("Fault occurred - " + ex.Message, SoapException.ClientFaultCode) Throw se End Try End Function

23 Database Class Notes Don't name everything DatabaseClass Name the Project  DatabaseClass Name the.vb module  DBClass Name the class  Cdatabase Check the project properties to determine the imports name to use in the application

24 Database Class Private cn As New OleDbConnection() Private adpt As New OleDbDataAdapter() Private m_SQLString As String Public Sub New() End Sub Public Property SQLString() Get Return m_SQLString End Get Set(ByVal Value) m_SQLString = Value End Set End Property

25 Database Class Public Function GetDataSet(ByVal ds As DataSet) As Boolean Try If Not OpenConnection() Then Throw New ApplicationException("Connection Open Failure") End If adpt = New OleDbDataAdapter(m_SQLString, cn) adpt.Fill(ds, "Messages") adpt.Dispose() Catch ex As Exception Throw New ApplicationException("Database Error - " + ex.Message) Finally cn.Close() cn = Nothing End Try Return True End Function

26 Database Class Private Function OpenConnection() As Boolean Try If cn.State <> ConnectionState.Open Then cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\...\Guestbook.mdb" cn.Open() Return True End If Catch ex As Exception Throw New ApplicationException("Connection Failure - " + ex.Message) End Try End Function


Download ppt "Visual Basic.NET Programming March 3, 2004. Agenda Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team)"

Similar presentations


Ads by Google