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 - Working with DataTableReader
ODP.NET - Working with DataTableReader
DataTableReader is complementary to a DataTable object, and is mainly used as a type of Data Reader in the disconnected mode. The following is the modified code:
Sample Code
- '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()
- Dim dtr As DataTableReader = dt.CreateDataReader
- 'check if it has any rows
- If dtr.HasRows Then
- 'read the first row
- dtr.Read()
- 'extract the details
- Me.txtEname.Text = dtr("ename")
- Me.txtSal.Text = dtr("sal")
- Me.txtJob.Text = dtr("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
Copyright exforsys.com
You can observe the highlighted code, which creates a DataTableReader object by calling the CreateDataReader method related to the DataTable object. Once the DataTableReader is created, we can directly retrieve the column values with the specified column names as follows:
Me.txtEname.Text = dtr("ename")
Me.txtSal.Text = dtr("sal")
Me.txtJob.Text = dtr("job")
Comments
Sponsored Links
