Popular Posts

Saturday, March 21, 2009

Data Adapter Connection Wizard

Data Adapter Configuration Wizard

In this section we will create our own data adapter, a built-in feature that comes with Visual Basic .NET and work with it. We will create our own table and access data from the newly created table. To start, create a new database in Access, name it as Books, create a table, Table1 with some columns in it and make sure the database is in the C: drive of your machine. To start creating your own DataAdapter, open a blank form and add a button (Button1) and a DataGrid control to it from the toolbox. Our intention here is to display the table or some columns from the table which we created in Access in the DataGrid control when Button1 is clicked. To display that, click on the Data tab in the toolbox and double-click OleDbDataAdapter object. We are using OleDbDataAdapter here as we are working with an OleDb data source. After you select OleDbDataAdapter from the data tab in the toolbox it gets added to the component tray beneath the form and opens the Data Adapter Configuration Wizard dialogue which looks like the image below.



The DataAdapter Configuration wizard let's you customize your data adapter as you want, example, displaying the whole table or displaying selected columns from the table and so on. Click the next button in the Data Adapter Configuration wizard to select the data connection you want to use. The dialogue that opens look like the image below. It allows you to choose the data connection.



Since we are working with the table we created, click the "New Connection" button in this dialogue box which opens the Data Link properties window. The Data Link Properties window looks like the image below.



In the Data Link properties window, select the Provider tab and select "Microsoft Jet 4.0 OLE DB Provider" from the list of available providers. After selecting the provider, select the Connection tab. Click on the ellipse where it says "Select or enter a database name" and browse for the database on the local drive. Since we are working with our own database (Books.mdb) located on the C: drive select that. Click on the "Test Connection" button to test the connection and if the connection succeeds click OK. Clicking OK display a dialogue box like the image below.



It's at this stage we will generate the SQL Statements to be used with this data adapter. Click next on this dialog box which takes you to another dialogue box like the image below.



It's here we build our SQL Queries. We can display the entire table in the DataGrid or just some columns from the table. To display data, click on the Query Builder button on this dialog box to build your queries. Once you click that button a new dialog box opens up with a list that displays all the tables in the database with which we are working. In this case it displays only one table as we created only one table in the Books database. Select Table1 and click Add. Table1 is added to the Query Builder window. You can select entire table to be displayed in the DataGrid or just some columns. To display entire table in the DataGrid select the checkbox named "All Columns" in the small dialog named "Table1" which automatically builds the SQL statement for us. If you want to display specific columns from the table in the DataGrid check on the columns you want to display. Once you finish with your selection, click next. The dialogue box that opens when you click next looks like the image below.



This dialogue lists the configuration of the data adapter and the results. Click finish to close the Data Adapter Configuration wizard.

That creates the data adapter, DataAdapter1, we need. Next step is to create a DataSet and connect this DataSet to the DataGrid using the DataSource and DataMember properties.

NEXT>> Continue Reading

No comments:

Post a Comment