visual basic.net programming march 3, 2004
DESCRIPTION
Visual Basic.NET Programming March 3, 2004. Agenda. Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team). Questions. All homework homework due by Friday. Web Site will remain available for awhile, if not, contact me, I'll have the material. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/1.jpg)
Visual Basic.NET ProgrammingMarch 3, 2004
![Page 2: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/2.jpg)
Agenda
• Questions / Discussion
• Cookies
• Project Work (Ends Around 9:00 PM)
• Demo's (15 minutes per team)
![Page 3: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/3.jpg)
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.
![Page 4: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/4.jpg)
![Page 5: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/5.jpg)
Cookies
![Page 6: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/6.jpg)
Cookies• 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.
![Page 7: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/7.jpg)
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.
![Page 8: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/8.jpg)
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).
ExampleDim cookie as HttpCookie
cookie = New HttpCookie("MyCookie","MyCookieValue")
Response.Cookies.Add(cookie)
![Page 9: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/9.jpg)
Cookies
Cookies are read from the Cookies collection of the ASP.NET Request object (available through the Request property of the Page Class).
ExampleDim cookie as HttpCookie
cookie = Request.Cookies("MyCookie")
Label1.Text = cookie.Value
![Page 10: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/10.jpg)
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.
![Page 11: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/11.jpg)
![Page 12: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/12.jpg)
Topics Covered in the
Visual Basic.NET ProgrammingCourse
![Page 13: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/13.jpg)
Console Application
Command Window
Console Application
![Page 14: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/14.jpg)
Windows Form Class
Input Screen
Windows Form Application
![Page 15: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/15.jpg)
Constructors
Fields
Get Set Properties
Methods
Windows Form Class
Class
Input Screen
Windows Form with Class DLL
![Page 16: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/16.jpg)
Database
Constructors
Fields
Get Set Properties
MethodsWindows Form
Class
ClassInput Screen
Windows Form, Class DLL, and ADO
![Page 17: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/17.jpg)
WebForm Class
Browser (IE6)
WebForm Application
Code Behind File
![Page 18: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/18.jpg)
Database
Constructors
Fields
Get Set Properties
Methods
WebForm Class
ClassBrowser (IE6)
WebForm, Class DLL, and ADO
Code Behind File
![Page 19: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/19.jpg)
Database
Constructors
Fields
Get Set Properties
Methods
WebForm Class
ClassBrowser (IE6)
Web Services using localhost
Code Behind File
SOAP
![Page 20: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/20.jpg)
Database
Constructors
Fields
Get Set Properties
Methods
WebForm Class
ClassBrowser (IE6)
Web Services using Remote Host
Code Behind File
Client Server
SOAP
![Page 21: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/21.jpg)
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
![Page 22: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/22.jpg)
Web Service <WebMethod()> _
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
![Page 23: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/23.jpg)
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
![Page 24: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/24.jpg)
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
![Page 25: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/25.jpg)
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
![Page 26: Visual Basic.NET Programming March 3, 2004](https://reader034.vdocuments.site/reader034/viewer/2022051116/56815022550346895dbe06a1/html5/thumbnails/26.jpg)
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