Sponsored Links
ODP.NET Tutorials
- Getting Started with Oracle and ODP.NET
- ODP.NET - Fundamental ODP.NET Classes to Retrieve Data
- ODP.NET - Retrieving Data Using OracleDataReader
- ODP.NET - Retrieving Multiple Rows on to the Grid
- ODP.NET - Retrieving Typed Data
- ODP.NET - Filling a DataTable Using OracleDataReader
- ODP.NET - Retrieving a Single Row of Information Using OracleDataAdapter
- ODP.NET - Working with DataTableReader
- ODP.NET - Populating a Dataset with a Single Data Table
- ODP.NET - Populating a Dataset with Multiple Data Tables
- ODP.NET - Presenting Master-Detail Information Using a Dataset
- ODP.NET - OracleCommand Object
- ODP.NET - Handling Nulls when Executing with ExecuteScalar
- ODP.NET - Handling Nulls when Working with OracleDataReader
- ODP.NET - Working with Bind Variables together with OracleParameter
- ODP.NET - Working with OracleDataAdapter with OracleCommand
- ODP.NET - Techniques to Improve Performance while Retrieving Data
Tutorials
ODP.NETODP.NET - Populating a Dataset with Multiple Data Tables
ODP.NET - Populating a Dataset with Multiple Data Tables
Now, let us add more than one data table into a dataset The following code retrieves a list of department details into a data table named Departments and another list of employee details into a data table named Employees:
- Imports Oracle.DataAccess.Client
- Public Class Form7
- Private Sub btnData_Click(ByVal sender As
- System.Object, ByVal e As System.EventArgs) Handles
- btnData.Click
- 'create connection to db
- Dim cn As New OracleConnection("Data Source=xe; _
- User Id=scott;Password=tiger")
- Try
- Dim ds As New DataSet
- Dim adp As OracleDataAdapter
- adp = New OracleDataAdapter("SELECT deptno,
- dname, loc FROM Dept", cn)
- adp.Fill(ds, "Departments")
- adp.Dispose()
- adp = New OracleDataAdapter("SELECT empno, ename,
- job, mgr, hiredate, sal, comm, deptno FROM
- Emp", cn)
- adp.Fill(ds, "Employees")
- adp.Dispose()
- Me.DataGridView1.DataSource = ds
- Me.DataGridView1.DataMember = "Departments"
- Me.DataGridView2.DataSource =
- ds.Tables("Employees")
- Catch ex As Exception
- 'display if any error occurs
- MessageBox.Show("Error: " & ex.Message)
- 'close the connection if it is still open
- If cn.State = ConnectionState.Open Then
- cn.Close()
- End If
- End Try
- End Sub
- End Class
From the above highlighted code, you can easily observe that we are retrieving two different result sets (identified by Departments and Employees) into the same dataset. The following code fragment creates the Departments data table:
adp = New OracleDataAdapter("SELECT deptno, dname,
loc FROM Dept", cn)
adp.Fill(ds, "Departments")
adp.Dispose()
The following code fragment creates the Employees data table:
adp = New OracleDataAdapter("SELECT empno, ename, job,
mgr, hiredate, sal, comm, deptno FROM Emp", cn)
adp.Fill(ds, "Employees")
adp.Dispose()
Those two result sets are automatically created as two data tables within the same dataset. Once the dataset is populated, we can present them with two different grids (two different methods) as follows:
Me.DataGridView1.DataSource = ds
Me.DataGridView1.DataMember = "Departments"
Me.DataGridView2.DataSource = ds.Tables("Employees")
The output for this code would look similar to the following figure:

Comments
Sponsored Links
