Presentation is loading. Please wait.

Presentation is loading. Please wait.

Working With Databases

Similar presentations


Presentation on theme: "Working With Databases"— Presentation transcript:

1 Working With Databases
In Visual Basic

2 Data Sources Data Sources for your VB Applications may include files in the following and other formats: MS Access MS Excel MS FoxPro dBase Lotus Comma Delineated Text

3 What is a database? “An organized collection of data”
Built in methods exist to help us access data from databases.

4 Tables Databases may include several separate sets of data called tables. Each table typically represents a different type of data. One table may cover customers, another may handle products, for instance.

5 Database Tables Our Store Inc. Customers Orders Products

6 Records and Fields Each table is divided into ROWS, often referred to as RECORDS, and COLUMNS, also known as FIELDS. A record contains the information about one particular thing. A field is one particular type of data.

7 Records and Fields This all makes more sense in visual format.
The rows, or records, show related data. The columns, or fields, represent the individual pieces of information each record has.

8 Recordsets Recordsets are the information your program pulled out of the database to work with.

9 SQL SQL, or Sequel, is a language used for interacting with databases.

10 Creating a recordset with SQL
Sample SQL: Select * From Employees; or Select ID, LastName, FirstName, SSN From Employees Where LastName = ‘Smith’;

11 SQL There are about 300 Keywords in SQL, but only about a dozen that are essential for most queries and updates. The Data control and the optional Microsoft ADO controls handle a lot of this for you.

12 Two Controls The Data Control is in the standard toolbox and handles basic database interaction The Microsoft ADO control is an added control. Much can be done via the automatic functionality, but you may wish to code your interaction for more control.

13 Database Options The visual data manager can be used to make simple databases. I recommend using MS Access. There are two MS Access databases in the full implementation of VB: NWIND.MDB and BIBLIO.MDB.

14 Database Interaction with the VB Application Wizard
The book does not list the first steps. You will remember the application wizard from the first chapter. See Pages 583 ff.

15 Common Database Actions
.MoveFirst .MoveLast .MoveNext .MovePrevious dtaCust.Recordset.Movefirst

16 EOF and BOF To make sure you stay within the records of the database without error, you may add some code to see if you are at the beginning of (BOF) or end of (EOF) of the table. If not adoBooks.Recordset.EOF then

17 Connecting datMyData.RecordSource = “select Address,City,CompanyName,ContactName,ContactTitle,Country,CustomerID,Fax,Phone,PostalCode,Region from Customers” ConnectionString property is set via the Custom ADO Control. It can also be copied and set manually if you wish.

18 Binding Each text box, label, or checkbox must be bound to a field. This is similar to our video picture box being bound to the multimedia control. DataField property associates this DataSource indicates the data control associated with the text box (or other control).

19 MSAccess Access is available on numerous campus computers.
The specific databases we are using may be on several computers (rm. 1013).

20 Access Click on design view to change the data types. For instance, you may wish to save the data as numbers or as text. The first field is usually a Primary Key, or Index. Each record’s index or primary key has a unique value. That is necessary since even a value such as Name or Social Security Number may be repeated or inapplicable. Double click on the table to view the data in it.

21 Summary Databases and VB interaction are subjects warranting books and classes of their own. We just touch the surface here.


Download ppt "Working With Databases"

Similar presentations


Ads by Google