Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.

Similar presentations

Presentation on theme: "Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control."— Presentation transcript:

1 Data Base

2 Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control. Bind and display data from databases to textbox and label controls. Write procedures to navigate table rows in a dataset. Display a row number on a form. Create a parameterized query. Write procedures to perform data maintenance activities including Add, Edit, and Delete rows. Use data validation routines in a data maintenance program.

3 Database Files What is a data base? Use the internet to give me an answer

4 Answer: database – a special repository— sometimes a single file, sometimes multiple files—used to store and to retrieve information.

5 Relational database –What is a relational database? You find the answer for me:

6 Answer a specific type of database where data rows are stored in separate tables, and the tables are related to each other by key values

7 What we will use We will use Microsoft Access Perfect for small-sized, individual user or small group systems. We will look at how and access can work together.

8 How do we connect the two? VB.NET uses ADO.NET – a database technology that supports connection to different database products. ADO.NET stores and transfers data using the Extensible Markup Language (XML). ADO.NET uses two basic types of connections to databases across networks: SQLClient – used to connect to Microsoft's SQL Server DBMS. We won’t use this one OLEDB – used to connect to all other database formats. We will use this one.

9 Database Concepts and Terminology A database stores data about individual entities in separate tables. Examples of entities in a school setting include Students, Courses, and Enrollment in courses.

10 DataBase Example

11 Sample data from a database

12 Table Explained Each table consists of rows and columns. Row = row for an individual student; also referred to as a record. Column = field of data stored for each student such as the SSN, Last Name, First Name, etc.

13 provides controls that you add to a form that are used to connect to and manage data in a database table. Columns from a database table are bound to database controls. Some of the controls you've already used such as labels, textboxes, and combo boxes can be found to database columns. Other special data controls such as the DataGrid and DataList controls need to be looked at.

14 Connecting VB and a database Configure a connection. The connection links to a data source – a data source is either a specific database file and/or a server computer. Configure a data adapter. A data adapter handles data retrieval and updating. The data adapter creates a dataset. A dataset stores rows that have been retrieved. Add controls to the form and set properties of the controls to bind the controls to the columns of a specific table in the dataset. Write VB code to fill the dataset.

15 Storing your database You should always store your database file on drive and folder: C:\Temp – this needs to be setup on your computer. Why… because of network security issues you will need to copy the database each day to the temp folder.

16 Creating a Connetion We will use OleDbConnection

17 Class Exercise Copy the VBUniv.Mdb Microsoft Access database from the class server to your client computer to drive and folder: C:\Temp

18 Starting the project Download the VBUniv.Mdb Microsoft Access database to the c:\temp Begin a new project – name it Database Name the form frmStudent. Copy the VBUniv.MDB database file from C:\Temp to your project folder. This will be a copy for use in the event that the file on C:\Temp becomes corrupted.

19 Configuring a Data Adapter and Connection Add a data adapter by using the Data Adapter Configuration Wizard – add the OleDbDataAdapter control from the toolbox Data tab by double-clicking


21 New Connection….

22 Data Link Properties

23 The Connection tab Locate the VBUniv.MDB database file at C:\Temp. Leave the User name as Admin with no password—a password is not needed for Microsoft Access as it is basically a single- user database management system. Click the Test Connection button. The connection should succeed if it doesn't, use the Browse button again to ensure you have the correct database or use the Provider tab to ensure you have the correct OLE DB Provider.


25 Choose a Query Type For Microsoft Access, you have a single choice – Use SQL statements A query is a SQL command that retrieves the desired data rows and columns from a database table.


27 Query Builder


29 Click the Query Builder button. All of the tables in the VBUniversity database (States, Course, Enrollment, and Student) are listed. If the Add Table window is not shown, right- click on the Query Builder window to open the Add Table window. Select the Student table and close the Add Table window.

30 Why use the Query Builder The Query Builder window interface is used to select the columns from the STUDENT table to include in the SQL Select statement. The columns (fields) are selected in the order in which they are checked. Notice that the output will be sorted by student's LastName column. Select ONLY the StudentSSN, LastName, FirstName, and MiddleInitial columns. You can specify the data rows to be sorted by last name.


32 Finishing up Examine your VB project form. You will discover the addition of two controls in the component tray named OleDbDataAdapter1 and OleDbConnection1. Rename the OleDbConnection1 control conVBUniversity.

33 Defining a Dataset Select the OleDbAdapter named daStudent, Select Generate Dataset from the Data menu, or Right-click and select from the shortcut menu. Name a dataset with the prefix "ds"—here we will name the dataset dsStudent.


35 After you click OK, you'll see the dataset listed in the system tray with the name DsStudent1 – Visual Basic automatically adds the digit 1 to the first dataset, 2 to the second dataset, and so forth.

36 The Fill Method At runtime, the data adapter's Fill method is executed to fill the dataset. This is usually coded in the Form_Load event for Windows applications. Examples: ‘DataAdapterName.Fill(DataSetName) daStudent.Fill(DaStudent1) When there is more than one table in a dataset, you can specify the dataset name and table name. daStudent.Fill(DsStudent1, "Student")

37 Binding Data to Controls A dataset is bound to controls on a form by setting control properties. When binding to a DataGrid, these properties include the: DataSource property – set it to the name of the dataset. DataMember property – set it to the name of the table.

Download ppt "Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control."

Similar presentations

Ads by Google