Home
Reviews
ODP.NET
ODP.NET - Retrieving Data Using OracleDataReader
Using keyword in Visual Basic 2005
This tutorial is part of a ODP.NET tutorial series. Read it from the beginning and learn yourself.
Reviews
ODP.NETTable of Contents
ODP.NET - Retrieving Data Using OracleDataReader
Using keyword in Visual Basic 2005Using keyword in Visual Basic 2005
Page 2 of 2
Author: Packt Publishing Published on: 5th Apr 2008 | Last Updated on: 9th Apr 2008
ODP.NET - Retrieving Data Using OracleDataReader
Using 'Using' for Simplicity
The above program can be made simple by using the Using statement together with ODP.NET classes as follows:
Ads
Sample Code
- Using cn As New OracleConnection("Data Source=xe;
- User Id=scott;Password=tiger")
- Try
- cn.Open()
- Dim SQL As String
- SQL = String.Format("SELECT ename, sal,
- job FROM emp WHERE empno={0}", Me.txtEmpno.Text)
- Using cmd As New OracleCommand(SQL, cn)
- Using rdr As OracleDataReader = cmd.ExecuteReader
- If rdr.HasRows Then
- 'read the first row
- rdr.Read()
- 'extract the details
- Me.txtEname.Text = rdr("ename")
- Me.txtSal.Text = rdr("sal")
- Me.txtJob.Text = rdr("job")
- Else
- 'display message if no rows found
- MessageBox.Show("Not found")
- End If
- End Using
- End Using
- Catch ex As Exception
- MessageBox.Show("Error: " & ex.Message)
- If cn.State = ConnectionState.Open Then
- cn.Close()
- End If
- End Try
- End Using
Copyright exforsys.com
The Using keyword is new in Visual Basic 2005, which internally generates try and finally blocks around the object being allocated and calls Dispose() for you saving you the hassle of manually creating it.
Ads
The objects created using the Using keyword are automatically erased (and respective resources would be automatically cleared) from the memory once it is out of using scope. Even though it is very flexible to use the Using statement, for the sake of clarity, we will go without using it in the examples of this book.
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







