Exforsys

Home arrow Reviews arrow ODP.NET

Pulling Information Using Table Name

Page 2 of 2
Author: Packt Publishing     Published on: 5th Apr 2008    |   Last Updated on: 9th Apr 2008

ODP.NET - Retrieving Multiple Rows on to the Grid

Pulling Information Using Table Name

In all of the previous examples, the SELECT statement was used to retrieve a set of rows. The SELECT statement is a good choice if you would like to retrieve only specific columns or to include some complex combinations using sub-queries, joins etc.

Ads

You can also retrieve a complete table (without using a SELECT statement) by setting the CommandType of OracleCommand to TableDirect. The following code demonstrates the use of TableDirect:

Sample Code
  1. Imports Oracle.DataAccess.Client
  2.  
  3. Public Class Form2
  4.   Private Sub btnGetEmployees_Click(ByVal sender As 
  5.     System.ObjectByVal e As System.EventArgs) Handles 
  6.     btnGetEmployees.Click
  7.     'create connection to db
  8.     Dim cn As New OracleConnection("Data Source=xe; _
  9.       User Id=scott;Password=tiger")
  10.     Try
  11.       Dim SQL As String
  12.       'build the SELECT statement
  13.  
  14.       Dim cmd As New OracleCommand("emp", cn)
  15.       cmd.CommandType = CommandType.TableDirect     
  16.       cmd.Connection.Open()
  17. ...
  18.   End Sub
  19. End Class
Copyright exforsys.com


Ads

The default CommandType is Text, which accepts any SQL statement. When we change it to TableDirect, it accepts only a table name. Another command type available is StoredProcedure. It is mainly used when you want to execute stored procedures using an OracleCommand object. (Working with PL/SQL stored procedures is covered in Chapter 5.)



 
This tutorial is part of a ODP.NET tutorial series. Read it from the beginning and learn yourself.

ODP.NET

 

Comments