I. CONNECTING TO ORACLE USING VB.NET

 1. Follow these steps to create a Visual Basic Windows Application project:
    a. Start Microsoft Visual Studio .NET.
    b. On the File menu, point to New, and then click Project.
    c. Click Visual Basic Projects under Project Types, and then click Windows Application under
        Templates. Choose Name and Location and click OK to open the project. By default, Form1
        is added to the project.

2. On the Project menu, click Add Reference, and then set a reference for System.Data.OracleClient by double-clicking.

3. On the left side of VB windows, there is Toolbox icon. Click on Toolbox and then on Data. A list of objects will be shown. Select OracleDataAdapter and drag and drop it on the VB form. The Data Adapter Configuration Wizard should show up. Then click on Next to continue.

4. On the Data Adaptor Configuration Wizard. Click on “New Connection.”

5. In Data Link Properties, choose Microsoft OLE DB Provider for Oracle as the provider, then click Next.

6. In Connection tab, enter devdb as the server name, and enter your username and password. Check "Allow saving password" box. To make sure that you are connected to the Oracle database, click on "Test connection". If connected, then "Test connection succeeded." message will show. Close the message window.

7. Click OK in the Data Link Properties window. Data Connection Wizard will create a new data adapter automatically and it will be your default connection to the database. Click Next to continue.

Here are some terms defined to help you understand the concepts.

Dataset is a set of data from the database.

Data adapters are used to exchange data between a data source and a dataset. In our case, this means reading data from the Oracle database into the dataset, and then writing changed data from dataset back to the database.

8. Select  “Use SQL statements"  radio button. Then Click Next.

9. Click Query Builder.

10. We will use the Query Builder to generate the query for us. You can see all the tables in your database. Choose table S_ORD. Click Add. Then click Close to close the Add Table window.

11. Check the box for all columns, then click OK.

12. Click Next to continue

13. Visual Basic will generate SELECT, INSERT, UPDATE and DELETE statements inside VB form which allows VB application to insert, update or delete a record within Oracle database. You will see the View Wizard Results Box, then click Finish.



A pop-up window with title "Do you want to include the password in the connection string?" opens up. Click the button "Include password".

14.  The data adapter that we just created is OracleDataAdapter1. Right click (locate in bottom window), then Properties and Name field. Clear it  and rename it  to daOrder.

15. Right click on daOrder data adapter that you just created. Select Generate Dataset. Change the default dataset name DataSet1 to dsOrder. Since we have only S_ord table in the form, VB knows that we are creating a new dataset for S_ord table. If we have multiple table in the form, then you will need to select the checkbox for which table you want VB generate the dataset for. In this case, we have only S_ord table to select. Click OK when you finish.

In the following step, we need to create several objects such as textboxes, labels, buttons, datagrid to display the data that populate from Oracle database fields: CustomerID, OrderID, SaleRepID, Date_ordered, Date_Shipped, etc.

  • Click on ToolBox in the left pane and then Windows Forms. Select Labels, Buttons, DataGrid (one at a time), and drag and drop them to the Form. The form should look like this:

Now right click on each objects you just created, select Properties, change its name in Name field as follows:

Datagrid is the standard control for viewing data in the .NET environment. It displays database information in a HTML table. In order to have the Datagrid display something, we need to bind the datagrid with some collection of information, like to a database or a dataset.

16. Now, we need to bind these text boxes with appropriate field names that exist in S_ORD table in the database. Right click on one of the text box (here I choose Customer ID), select Properties and under DataBindings, in Text field, navigate through S_Ord table, then click on Customer_ID. Repeat this step until all the text boxes are bound with field name in the S_Ord table.

17. Now, we need to bind DataGrid to the S_ord table so we can populate data. Right click DataGrid, select Properties, then in DataSource field select dsOrder (which is the data set you created earlier and changed its name). Then in DataMember, select S_Ord. Close it when you finish.

18. Double click on your form to open Form1_load, then we fill the dataset with following command:

19. By now, you should have created 7 buttons , which you will use to navigate through the database records and use for updating, deleting or adding a record to the database. You should have the following buttons in your form: Next, Previous, Begin, Last, Save/Update Order, Delete Order, Add new Order buttons.

Double click on each button you created, then add the following code. This code is used to navigate through the records in the S_ORD table in the database.

20. Double click on the button that you will use to Add a new order, Delete an order, Save or Update an order. Here is how the code should look like.

21. Click Debug, then Start in the VB main menu to run the form. And your form should look like:

.

II. CONNECTING TO MULTIPLE TABLES USING VB.NET

Link for CONNECTING TO MULTIPLE TABLES USING VB.NET