Presentation is loading. Please wait.

Presentation is loading. Please wait.

VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY.

Similar presentations


Presentation on theme: "VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY."— Presentation transcript:

1 VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY

2 Presented by

3 Contents Introduction to Data connectivity Different Database Approach
DAO ADO Simple Connectivity program using Data Control

4 Introduction to Data Connectivity
What is Database Connection? A database connection is a facility in computer science that allows client software to communicate with database server software, whether on the same machine or not. A connection is required to send commands and receive answers.

5 Simple database Field Record Table ID No 1 2 3 Bob Jones Mary Rodgers
Sue Williams Name Date of Birth 01/04/58 Weight Height Field Record Table 11/22/61 06/11/57 72 65 68 170 125 130

6 FRONT END AND BACK END APPROACH
The place to access the data or the place from which the data can be accessed through connectivity. Back-End: Place where the datas can be maintained (or) stored. Ex : Ms-Access

7 FRONT END AND BACK END APPROACH(Continued…)
Connectivity Bridge Back-End Application Front-End Report Database Records

8 Data Connection Approaches
Data Control based non-programming associated with form based controls (DataGrid, DataList etc) Limited control over data Programming based uses Connection object (ADO) allows closer data control

9 Different Database Connectivity Approaches.
Two Data Object Library approaches DAO (Data Access Objects) Closely linked to MS Access Original access strategy (up to VB6) ADO (ActiveX Data Objects) Newer approach More generic Same approach for ASP (VB Script active server pages)

10 DAO Once the data structure is developed, one can develop the user interface. With VB the user can access the data through the data control. It connect you to the database and specific data set. Once the data connection is made you can bind other controls to the data control.

11 Features Establish the connection with Database.
Returns set of records fronm database. Enables the user to move from record to record. Enables the user to display and manipulate data from the records in bound controls.

12 A Visual Basic application cannot directly interact with a database
There are two intermediate components between the application and the database data control database engine

13 Data control It is a Visual Basic object
It connects the application to the database via the database engine. It is the conduit between the application and the engine, passing information back and forth between the two

14 Database engine I It is the heart of a Visual Basic database management system It is the actual software that does the management. Having this engine saves programmers a lot of work. The database engine native to Visual Basic is known as the Jet engine.

15 Database Engine (continued)
It is the same engine used by Microsoft Access for database management. Hence, it is primarily used to work with Access databases, but it can also work with others. It requires less code to connect to an existing database. View all information within that database

16 Database Engine (continued)
modify any and all information within that database Add and delete all information within that database

17 How Data Control works? Two properties need to set during run time or design time. Database name-This specifies the name of the database that must be opened. Record Source- This specifies the name of the table of the database from which the data has to be extracted.

18 After setting this properties Vb connects to the database specified and returns set of records from the table in the form of recordset. Record Set: It is an object that points to the data in the database based on record source property of data control. The record source property can be the name of the table and database selects fields from one or more tables.

19 Setting The Properties For Data Control
DESCRIPTION BOF Returns True when the current record is Positioned before any data. EOF Returns True when the current record is positioned past any data. Caption Phrase displayed on the data control. Connect Type of database. Default is Microsoft Access (or Jet).

20 Setting The Properties For Data Control
DESCRIPTION Database Name Returns or sets the name of the source database for the data control. Must be a fully qualified path and file name. Record set Type Indicates type of Recordset you want data control to create. 1.Table 2. Dynaset 3. Snapshot. Record Source Determines the table (or virtual table) the data control is attached to. Bound Controls To view the information, we use data bound controls that are special controls with properties established by database fields .They are Label, Text box, Check box, Image, OLE, Listbox, Picture, Combobox.

21 DAO Data Control Recordset Methods
Important Recordset methods are: AddNew -Adds a new record to the Recordset. All fields are set to null and this record becomes the current record. CancelUpdate -Used to cancel any pending updates (either with Edit or AddNew method) Close -Closes a Recordset. Delete -The current record is deleted from the Recordset.

22 DAO Data Control Recordset Methods (continued)
Edit Places the current record in the Recordset into edit mode. MoveFirst Moves the current record pointer to the first record in the Recordset. MoveLast Moves the current record pointer to the last record in the Recordset. MoveNext Moves the current record pointer to the next record in the Recordset.

23 DAO Data Control Recordset Methods (continued)
MovePrevious Moves the current record pointer to the previous record in the Recordset. Requery Updates the data in a Recordset object by re-executing the query on which the object is based. Update Saves the current contents of all data bound controls.

24 ADO ADO Means active X Data Control.
ADO control works along with OLEDB. OLEDB provides the rights such as accessing, manipulating datas in a database.

25 Microsoft Components Jet Database Engine: VB’s database engine for MS Access & ISAM (Indexed Sequential Access Method) DBMSs ODBC (Open Database Connectivity): Interface for SQL relational databases RDO (Remote Data Objects): Original component to access databases across a network OLE DB (Object Linking & Embedding Databases): newer generic interface accessing SQL & nonSQL databases

26 ADO VISUAL BASIC 6.0 APPLICATION ADO OLE DB ODBC
SQL DATA NON SQL DATA OTHER e.g. MS Access (JET) Text Files, Excel LEGACY SQL Server, ORACLE etc SYSTEMS

27 Main Objects The ADO object model defines a collection of programmable objects that can be used by any of the Microsoft Visual languages The blue box represents object. The yellow box represents collection.

28 Key parts of ADO programming
Connection Command Parameter Recordset Field Error Property Collection Event

29 ADO Objects summary ADO OBJECTS DESCRIPTION 1.Connection
Provides connection between the application & the Database. 2. Command SQL statements to operate with datas 3. Parameter Arguments of an SQL statement 4. Recordset Provides accessing & manipulating records on the Database. 5.Field Column of a record set in a database table. 6. Error Produces error messages when error in connection. 7. Property Characteristics of an ADO object.

30 ADO COLLECTIONS SUMMARY
DESCRIPTION 1.Errors When connection failure occurs. 2.Parameters Argument included with command object. 3. Fields Fields Present in a Record Set. 4. Properties Connections , Command, Record set Field object properties.

31 How to give commands to that? Lets see the Answer for these question.
HOW TO USE ADO CONTROL? How to give commands to that? Lets see the Answer for these question.

32 Creating DSN Before using this control you have to create user DSN,for that you can use control panel or VB to create user DSN.   Via Windows Control Panel, double-click on Administrative Tools, then Data Sources (ODBC).

33 ODBC Double click this ODBC .It will display ODBC data source Administrator. The ODBC Data Source Administrator screen is displayed, as shown below. Click on the User DSN tab

34 ODBC(Continued) Select the user DSN. Now select ADD option.
Now Create New Data Source window displayed. It is used to list all the ODBC drivers for the connection. Click the Add button. The Create New Data Source dialog box will appear.

35

36 Select Microsoft Access Driver (
Select Microsoft Access Driver (*.mdb) from the list and click the Finish button

37 The ODBC Microsoft Access Setup dialog box will appear
The ODBC Microsoft Access Setup dialog box will appear. For Data Source Name, type Biblio. If desired, you can type an entry for Description, but this is not required.

38 Click the Select button. The Select Database dialog box appears
Click the Select button. The Select Database dialog box appears. On a default installation of VB6 or Visual Studio 6, the BIBLIO.MDB sample database should reside in the folder C:\Program Files\Microsoft Visual Studio\VB98. Navigate to that folder, select BIBLIO.MDB from the file list, and click OK.

39 When you are returned to the ODBC Microsoft Access Setup screen, the database you selected should be reflected as shown below. Click OK to dismiss this screen.

40 When you are returned to the ODBC Data Source Administrator screen, the new DSN should appear as shown below. Click OK to dismiss this screen.

41 ODBC(Continued) Close the ODBC data source Administrator & the control panel. Now you get into the Visual Basic.

42 Example Open Microsoft Visual Basic from Microsoft Visual Basic.
Open the Standard Exe Template. Now you cant see the ADO control button on the toolbox. So you have to take it from other components supported by Visual Basic. To get components right click on the Toolbox, select components.

43 Example-ADO(continued)
Now you can see a dialog box having three tab,Namely Controls Designers Insertable Objects Now you select controls from components dialog box. You just scroll down the controls listed there.

44 Example-ADO(continued)
After scrolling some objects,you can see “Microsoft ADO data control 6.0(OLEDB) Now you click on the check box present near by the control name.

45 Example-ADO(continued)
Then give Apply and close to disappear the components wizard.

46 Example-ADO(continued)
Now you can see a newly inserted control, just like a DAO control present in the toolbox.

47 Example-ADO(continued)
Place the ADO control on the form. Now you can see ADO control is present in the form with navigation buttons.

48 Example-ADO(continued)
After placing ADO control , get into the properties window of the ADO. Change name and caption properties of ADO. In properties window , select connection string property. Click on the button present in the connection string.

49 Example-ADO(continued)
A dialog box will be opened with the name property pages.

50 Example-ADO(continued)
In the property pages select “Use ODBC Data Source Name” Now click on the combo box present there. Then select a DSN created by you through control panel then give OK.

51 Example-ADO(continued)
Now select Record source property of the ADO control ,then select 2-adcmd Table option from command type and select a table from Table or Stored Prog option and give OK.

52 Example-ADO(continued)
Now the application is connected with MS-Access database. This an be checked by using Text boxes.

53 Example-ADO(continued)

54 Example-ADO(continued)
Select a text box and change the properties as given below. Data Source-Adodc1 Datafield- Fieldname Now run the program. Now the application gets connected to the specified Database.

55 Difference between DAO & ADO
You cant access any Enterprise controls like DBList,DBComb,ODBC connectivity and SQL structures. Applicable only for MS-Access. You can access ODBC connectivity and SQL structure. Applicable for remote client side data.

56 EXAMPLE using DAO

57 Importance of Text box It is used to view the records. With the help of text box the user can manipulate the datas of the selected table. Set the common bound properties: Select Text box control from toolbox. Place the textbox on the form Bring up the properties window. Click on “Data Source” property. Select the name of the data control from the dropdown list.

58 Set the common bound properties:(continued)
Now the data field property of the textbox will display the field from the record set return by the datacontrol. Click on the data field and select the required field from the drop down list. This text box is now bound to the field selected. Run the project.

59 Set the common bound properties:(continued)
Now text box will display current record of the record set. Once the navigation button is cllicked the user can mmove from one record to other record.It will display the field name selected column of the current record.

60 Using the DAO Procedure: Place the data control on your form.
Select the database from “Database name” property. Select the Record source from “Record source” property. Place the text box on your form. Select the source from “Data source ” property.

61 Using the DAO(continued)
Select the field name from “Data Field” property. Run the program.


Download ppt "VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY."

Similar presentations


Ads by Google