Thought Sharing

Tuesday, November 23, 2010

Database connectivity using DAO (Data Access Object) i.e. Data Control (Data1)

DAO Data Control uses Microsoft Jet Engine to connect VB application to MS Access database file for example Nwind.mdb. The steps of connectivity are as follows:
1.) Open visual basic application. Drag & drop a data control (Data1) and textboxes on the form.
2.) For Data control (Data1) specify two properties :
i.) DatabaseName: specify the name of database. Eg. Nwind.mdb
ii.) RecordSource: specify the name of table you want to connect to. Eg. Customers
3.) Now for displaying data in textboxes, we need to specify two properties:
i.) DataSourceName: specify the name of data control (Data1)
ii.) Datfield: specify the name of the field of table whose data is to be displayed in this textbox. For eg. Customer Name.
4.) Repeat the above step for all the data bound controls i.e. textboxes on the form.
5.) Now run the form by pressing F5 key, to show the data of Customer Table.