ASP.NET Binding and an Introduction to Database Queries Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
Introduction to SQL, OleDB interface to Access from VB.NET.
Advertisements

Website Security ISYS 512. Authentication Authentication is the process that determines the identity of a user.
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Authenticating Users in an ASP.NET Application. Web Site Administration Tool From VS 2008, click Website/ ASP.Net Configuration to open Web Site Administration.
ASP.NET and ADO.NET. ASP.NET Server Controls Intrinsic Controls: These controls correspond to their HTML counterparts. –Ex. Textbox, listbox, button,
VB.NET Database Tools ISYS Net Applications OLE DB Provider OLE DB Data Source OLE DB Provider ODBC Data Source SQL Server Data Source SQL Server.Net.
Coding ADO.NET Objects: Connection, Command, DataReader.
Website Security ISYS 512. Authentication Authentication is the process that determines the identity of a user. Web.config file – node Options: –Windows.
ASP.Net AJAX. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net, etc.
ASP.NET and ADO.NET. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB) Database.
Web Site Security ISYS 512/812. Authentication Authentication is the process that determines the identity of a user. Web.config file – node Options: –Windows:
Coding ADO.NET Objects: Connection, Command, DataReader.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Working with Session and Application Objects. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
VB.NET Database Tools ISYS 573. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
ASP.NET and ADO.NET. Bind the DataReader to a DataGrid Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" Dim objConn.
Coding ADO.NET Objects: Connection, Command, DataReader.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Website Security ISYS 512. Cookies Data in Cookies System.Web Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One.
ASP and HTML. Anchor Tag testAnchorTag Demo: ASPNet/ASPNETProdListSelf.ASPX.
Introduction to Structured Query Language SQL. SQL Select Command SELECT * FROM tableName WHERE criteria;
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
CIS 451: Using ASP.NET Objects with SQL Dr. Ralph D. Westfall February, 2009.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
1/36 Database Programming with Visual Basic.Net and MS Access IKE Lab. Yunho Song Database Management and Analysis.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
XML, DTD, ENTITY Please see speaker notes for additional information!
ASP.NET Presented by Pan Gao. ASP.NET Next generation of ASP Next generation of ASP Program Language to build web application Program Language to build.
ASP.NET - accessing the database - datareader vs dataset - datagrid vs datalist - brief look at web matrix.
XML and DTD Please you speaker notes for additional information!
Internet Programming ASP Sara Shahzad Dept. of Computer Science UOP.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
ASP.NET Database Connection. ASP.NET Framework The ASP.NET framework includes the ADO.NET data access technology for working with databases and other.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
ASP.Net and HTML. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data.
Command Object’s ExecuteNonQuery Method ISYS 512.
I want to do SQL, I start as if I am doing a regular query.
When I want to work with SQL, I start off as if I am doing a regular query.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Notes on ADO from other projects Please use speaker notes for additional information!
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Introduction to Oracle - SQL Additional information is available in speaker notes!
CIS 375—Web App Dev II ASP.NET 9 Database. 2 ADO.NET What is ADO.NET? ADO.NET is a part of the.NET Framework ADO.NET consists of a set of classes used.
MIS 3200 – Unit 3.2 Page_Load method AutoPostBack property of controls IsPostBack method of the Page object Understanding web page life cycle.
2314 – Programming Language Concepts Introduction to ADO.NET.
Coding ADO.NET Objects: Connection, Command, DataReader.
CIS 375—Web App Dev II ASP.NET 5 Events. 2 The Page_Load Event The Page_Load event is triggered when a page loads. [Example]Example Sub Page_Load lbl1.Text="The.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Using a Database Access97 Please use speaker notes for additional information!
PHP with MYSQL Please use speaker notes for additional information!
ADO and DataList, DataCombo and DataGrid Controls Please use speaker notes for additional information!
Coding ADO.NET Objects: Connection, Command, DataReader.
1 c6212 Advanced Database and Client Server MS SQL Server 2000 Stored Procedures and Parameters What ? Why ? How ?
Coding ADO.NET Objects: Connection, Command, DataReader
ASP.NET and ADO.NET.
Please see speaker notes for additional information!
VB.NET Using Database.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
CS 3870/CS 5870 Test 2 (50 points) Thursday
Coding ADO.NET Objects: Connection, Command, DataReader
Database Handling Class and Service
ASP.NET and ADO.NET.
Command Object’s ExecuteNonQuery Method
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

ASP.NET Binding and an Introduction to Database Queries Please use speaker notes for additional information!

My schedule sub Page_Load if Not Page.IsPostBack then dim myCourses=New ArrayList myCourses.Add("CIS13") myCourses.Add("CIS44") myCourses.Add("CIS45") myCourses.Add("CIS46") myCourses.Add("CIS47") myCourses.Add("CIS48") myCourses.Add("CIS49") myCourses.Add("CIS50") myCourses.Add("CIS53") myCourses.Add("CIS63") myCourses.Sort() crs.DataSource=myCourses crs.DataBind() end if end sub sub showSchedule(s as Object,e As EventArgs) lblSchedule.text=lblSchedule.text & " " & crs.SelectedItem.Text end sub <asp:DropDownList id="crs" runat="server" AutoPostBack="True" onSelectedIndexChanged="showSchedule" /> Since Page_Load is run every time the page is loaded this can be used to control running only on first time. The ArrayList is myCourses, the DropDown list has an id of crs. The DataSource property of the DropDownList is set to the Array List name and the DataBind() method of the DropDownList binds the data.

My schedule <!-- function __doPostBack(eventTarget, eventArgument) { var theform = document._ctl0; theform.__EVENTTARGET.value = eventTarget; theform.__EVENTARGUMENT.value = eventArgument; theform.submit(); } // --> CIS13 CIS44 CIS45 CIS46 CIS47 CIS48 CIS49 CIS50 CIS53 CIS63 CIS47 CIS50 CIS63

Sub Page_Load Dim sPath As String = Server.MapPath("\YourUserName\db\YourDB.mdb") Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0; DATA Source=" & sPath & ";" Dim objConn As OleDbConnection Dim cmdSelect As OleDbCommand Dim dtrReader As OleDbDataReader Dim strResults As String objConn = New OleDbConnection( connString ) objConn.Open() cmdSelect= New OleDbCommand( "SELECT SomeField From SomeTable", objConn) dtrReader= cmdSelect.ExecuteReader() While dtrReader.Read() strResults = strResults & dtrReader("SomeField") & " " End While lblResults.Text = strResults dtrReader.Close() objConn.Close() End Sub Suggested code from for using an Access database. “General Users can mimic the following code snipplet to connect to an MS Access database using ASP.Net (VB).”

Sub Page_Load Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0; DATA Source=" & sPath & ";" Dim objConn As OleDbConnection Dim cmdSelect As OleDbCommand Dim dtrReader As OleDbDataReader Dim strResults As String objConn = New OleDbConnection( connString ) objConn.Open() cmdSelect= New OleDbCommand( "SELECT DName From Donor2000", objConn) dtrReader= cmdSelect.ExecuteReader() While dtrReader.Read() strResults = strResults & dtrReader("DName") & " " End While lblResults.Text = strResults dtrReader.Close() objConn.Close() End Sub I uploaded donor.mdb to my site at brinkster in the db directory. This is the path. Output

Sub Page_Load Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0; DATA Source=" & sPath & ";" Dim objConn As OleDbConnection Dim cmdSelect As OleDbCommand Dim dtrReader As OleDbDataReader Dim strResults As String objConn = New OleDbConnection( connString ) objConn.Open() cmdSelect= New OleDbCommand( "SELECT DIdno, DName From Donor2000", objConn) dtrReader= cmdSelect.ExecuteReader() While dtrReader.Read() strResults = strResults & dtrReader("DIdno") & " " & dtrReader("DName") & " " End While lblResults.Text = strResults dtrReader.Close() objConn.Close() End Sub

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub

Donor2000 table in the access database donor.mdb. Results from program on previous page.

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT DIdno, DName, DYrFirst FROM Donor2000 where DYrFirst =" & "'1996'" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub

DIdno DName DYrFirst Mary Wilson Robert Brooks 1996

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT DIdno, DName, DYrFirst FROM Donor2000 order by DYrFirst" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT DName, DCity FROM Donor2000 Where DCity = " & "'Fall River'" & " or " & "Dcity = " & "'Braintree'" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub Note that I coded this all on one line and showed it on two lines only for the presentation.

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT Donor2000.DIdno, DName, DAmtCont FROM Donor2000, Donation2000 Where Donor2000.DIdno = Donation2000.DIdno" Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub The SELECT was coded on one line, I made it two lines to fit on the slide.

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT Donor2000.DIdno, DName, DAmtCont FROM Donor2000, " & _ "Donation2000 Where Donor2000.DIdno = Donation2000.DIdno" Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT Donor2000.DIdno, DName, Donation2000.DDriveNo, DDriveName, DAmtCont FROM Donor2000, Donation2000, Drive2000 Where Donor2000.DIdno = Donation2000.DIdno and Donation2000.DDriveNo = Drive2000.DDriveNo" Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub The SELECT was coded on one line, I wrapped when I pasted it on the slide.

Before Search

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() end sub

sub Get_Record(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000 where DName = '" & nameInput.Text & "'" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub Enter the Donor Name:

Prior to doing the add. After doing the Add and the the Display.

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() end sub

sub Add_Record(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "INSERT INTO Donor2000 VALUES('55555','Susan Ash', '12 Oak St', 'Braintree', 'MA', '02184','1997', 'Ann Smith')" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub Note that I coded this as one long string - I wrapped when I pasted on the slide.

sub Show_Records(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "Select * from Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub

After the add of This shows the screen after the submit has deleted the record. I then went back and ran datatest.aspx which shows all of the records is not there.

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() end sub sub Delete_Record(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";"

'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "DELETE FROM Donor2000 WHERE DIdno = '55555'" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub

I filled in the textboxes, clicked add and then clicked display.

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() end sub sub Add_Record(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";"

'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "INSERT INTO Donor2000 VALUES('" & idInput.Text & "', '" & nameInput.Text & "', '" & adrInput.Text & "', '" & cityInput.Text & "', '" & stateInput.Text & "', '" & zipInput.Text & "', '" & yrfstInput.Text & "', '" & contInput.Text & "')" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub sub Show_Records(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" I wrote this code as one long statement - easier I think to keep track of the quotes. I then wrapped when I pasted on the slide.

'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "Select * from Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub Enter the Donor ID: Enter the Donor Name: Enter the Donor Address: Enter the Donor City: Enter the Donor State: Enter the Donor ZIP: Enter the Donor Year First: Enter the Donor Contact:

I entered and clicked Delete. Then I clicked Display The results of the display.

sub Page_Load(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() end sub

sub Delete_Record(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "DELETE FROM Donor2000 WHERE DIdno = " & "'" & idInput.Text & "'" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub

sub Show_Records(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "Select * from Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() end sub Enter the Donor ID:

I keyed in 66666

I am going to give David a middle initial of A and change his contact to Roger Brown.

Changes I keyed in.

This shows the changes.

sub Page_Load(sender as Object, e as EventArgs) if Not Page.IsPostBack then Show_Records(sender, e) end if end sub sub Get_Record(sender as Object, e as EventArgs) enterlabel.visible = false getidInput.visible = false submitbtn.visible = false 'idlabel.visible = true 'idInput.visible = true namelabel.visible = true nameInput.visible = true addrlabel.visible = true addrInput.visible = true citylabel.visible = true cityInput.visible = true statelabel.visible = true stateInput.visible = true ziplabel.visible = true zipInput.visible = true yrlabel.visible = true yrInput.visible = true contlabel.visible = true contInput.visible = true updatebtn.visible = true displaybtn.visible = true 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";"

'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000 where DIdno = '" & getidInput.Text & "'” 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader() 'Set the textbox values objDataReader.Read() idInput.text = objDataReader("DIdno") nameInput.text = objDataReader("DName") addrInput.text = objDataReader("DStAdr") cityInput.text = objDataReader("DCity") stateInput.text = objDataReader("DState") zipInput.text = objDataReader("DZip") yrInput.text =objDataReader("DYrFirst") contInput.text = objDataReader("DContact") objDataReader.Close() 'Do the DataBinding objDataReader = objCommand.ExecuteReader() dgResults.DataSource = objDataReader dgResults.DataBind() 'Close the datareader/db connection objDataReader.Close() objConnection.Close() end sub

sub Update_Record(sender as Object, e as EventArgs) 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "UPDATE donor2000 SET " & _ "DName = '" & nameInput.text & "', " & _ "DStAdr = '" & addrInput.text & "', " & _ "DCity = '" & cityInput.text & "', " & _ "DState = '" & stateInput.text & "', " & _ "DZip = '" & zipInput.text & "', " & _ "DYrFirst = '" & yrInput.text & "', " & _ "DContact = '" & contInput.text & "' " & _ "WHERE DIdno = '" & idInput.text & "'" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) objCommand.ExecuteNonQuery objConnection.Close() Show_Records(sender, e) end sub

sub Show_Records(sender as Object, e as EventArgs) enterlabel.visible = true getidInput.text = "" getidInput.visible = true submitbtn.visible = true idlabel.visible = false idInput.visible = false namelabel.visible = false nameInput.visible = false addrlabel.visible = false addrInput.visible = false citylabel.visible = false cityInput.visible = false statelabel.visible = false stateInput.visible = false ziplabel.visible = false zipInput.visible = false yrlabel.visible = false yrInput.visible = false contlabel.visible = false contInput.visible = false updatebtn.visible = false displaybtn.visible = false 'Create a connection string Dim sPath As String = Server.MapPath("\pgrocer\db\donor.mdb") Dim connString as String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & sPath & ";" 'Open a connection Dim objConnection as OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'Specify the SQL string Dim strSQL as String = "SELECT * FROM Donor2000" 'Create a command object Dim objCommand as OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection)

'Get a datareader Dim objDataReader as OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) 'Do the DataBinding dgResults.DataSource = objDataReader dgResults.DataBind() end sub