Oracle Database Interaction Using ODP.NET and ASP.NET: All Possible Ways To Get Connected - Connecting to Oracle using ODP.NET (Oracle Data Provider for .NET)
(Page 5 of 6 )
ODP.NET is freely available from the Oracle Technology Network (OTN) at http://www.oracle.com/technology/software/tech/windows/odpnet/index.html. The types are contained in two namespaces: Oracle.DataAccess.Client (data access classes and enumerations) and Oracle.DataAccess.Types (classes and structures for Oracle data types). Both namespaces are in the assembly Oracle.DataAccess.dll (generally available in Oracle client installed directory). ODP.NET requires Oracle client version 9.2 or later.
Now we shall test an example of connecting to and accessing data from an Oracle database using ODP.NET.
Imports Oracle.DataAccess.Client
.
.
Dim cn As New OracleConnection("Data Source=ORCL;User
Id=scott;Password=tiger;")
Try
Dim da As New OracleDataAdapter("select * from
scott.emp", cn)
Dim dt As New OleDbData
da.Fill(dt)
da.Dispose()
Me.DataGrid1.DataSource = dt
Me.DataGrid1.DataBind()
dt.Dispose()
Cath ex As Exception
Me.lblError.Text = ex.Message
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
The explanation for the above code is very similar to that of the previous sections. But, you need to look carefully at the “imports” statement; it is a bit different from the others because we are using ODP.NET. The above example is demonstrated in “webform1” of the downloadable.
Next: ODP.NET (by Oracle) versus .NET Framework data provider for Oracle (by Microsoft) >>
More ASP.NET Articles
More By Jagadish Chaterjee