Home
Reviews
ODP.NET
This tutorial is part of a ODP.NET tutorial series. Read it from the beginning and learn yourself.
Reviews
ODP.NETODP.NET - Working with OracleDataAdapter with OracleCommand
Author: Packt Publishing Published on: 5th Apr 2008 | Last Updated on: 10th Apr 2008
ODP.NET - Working with OracleDataAdapter together with OracleCommand
In the previous examples, we worked with OracleDataAdapter by directly specifying SQL statements. You can also pass OracleCommand to OracleDataAdapter. This is very useful if you deal with stored procedures (covered in Chapter 5) or bind variables together with OracleDataAdapter.
Ads
The following is a simple example that uses OracleCommand together with OracleDataAdapter:
Sample Code
- Imports Oracle.DataAccess.Client
- Public Class Form10
- Private Sub btnGetEmployees_Click_1(ByVal sender As
- System.Object, ByVal e As System.EventArgs) Handles
- btnGetEmployees.Click
- 'create connection to db
- Dim cn As New OracleConnection("Data Source=xe; _
- User Id=scott;Password=tiger")
- Try
- 'create command object to work with SELECT
- Dim cmd As New OracleCommand("SELECT empno, _
- ename, job, mgr, hiredate, sal, comm, deptno _
- FROM emp", cn)
- 'create DataAdapter from command
- Dim adp As New OracleDataAdapter(cmd)
- 'create the offline data table
- Dim dt As New DataTable
- 'fill the data table with data and clear resources
- adp.Fill(dt)
- adp.Dispose()
- 'display the data
- Me.DataGridView1.DataSource = dt
- 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
Ads
You can observe from the above highlighted code that we created an OracleCommand object, and the OracleDataAdapter can accept OracleCommand as a parameter.
ODP.NET
- 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 - 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







