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
Home
Tutorials
ODP.NET
Tutorials
ODP.NETODP.NET Retrieving a Single Row of Information Using OracleDataAdapter
ODP.NET - Retrieving a Single Row of Information Using OracleDataAdapter
In the previous example, we worked with a set of rows in the DataTable object. Now, we shall work with a particular row using the DataTable object. The following code accepts an employee number from the user and gives you the details of that employee:
Sample Code
- Imports Oracle.DataAccess.Client Public Class Form3 Private Sub btnGetEmployee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetEmployee.Click 'create connection to db Dim cn As New OracleConnection("Data Source=xe
_ User Id=scott Password=tiger") Try Dim SQL As String 'build the SELECT statement SQL = String.Format("SELECT ename, sal, job FROM emp WHERE empno={0}", Me.txtEmpno.Text) 'create the dataadapter object Dim adp As New OracleDataAdapter(SQL, cn) 'create the offline datatable Dim dt As New DataTable 'fill the data table with rows adp.Fill(dt) 'clear up the resources and work offline adp.Dispose() 'check if it has any rows If dt.Rows.Count > 0 Then 'extract the details Me.txtEname.Text = dt.Rows(0)("ename") Me.txtSal.Text = dt.Rows(0)("sal") Me.txtJob.Text = dt.Rows(0)("job") Else 'display message if no rows found MessageBox.Show("Not found") End If 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
Copyright exforsys.com
Once the DataTable object is filled using OracleDataAdapter, we can directly retrieve a particular row using the row index. Once the row is fetched, we extract column values by providing column names for the rows as follows:
Me.txtEname.Text = dt.Rows(0)("ename")
Me.txtSal.Text = dt.Rows(0)("sal")
Me.txtJob.Text = dt.Rows(0)("job")
The output for the above code would look similar to the following figure:

Read Next: Getting Started with Oracle and ODP.NET
Comments
Sponsored Links
