Microsoft Knowledge Base Email Alertz

KBAlertz.com: (308071) - This article demonstrates how to use the ADO.NET OleDbDataReader class to retrieve data from an Oracle database. Requirements The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 308071 - Last Review: May 13, 2007 - Revision: 2.3

How To Access an Oracle Database by Using the OleDbDataReader and Visual Basic .NET

This article was previously published under Q308071

On This Page

SUMMARY

This article demonstrates how to use the ADO.NET OleDbDataReader class to retrieve data from an Oracle database.

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
  • Microsoft Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, or Windows NT 4.0 Server
  • Microsoft Data Access Components (MDAC) version 2.6 or later
  • Oracle Client tools (installed on the computer)
  • Microsoft Visual Studio .NET
This article assumes that you are familiar with the following topics:
  • Visual Studio .NET
  • ADO.NET fundamentals and syntax
  • Oracle connectivity

Steps to Retrieve Data from an Oracle Database

  1. In Oracle SQL*Plus or any Oracle Client tool that allows you to run data definition language (DDL) statements, follow these steps:
    1. Create a table named TestTable as follows:
      Create Table TestTable (c1 char(5));
      						
    2. Insert data into TestTable as follows:
      Insert into TestTable c1 values('Test1');
      Insert into TestTable c1 values('Test2');
      Insert into TestTable c1 values('Test3');
      						
  2. Start Visual Studio .NET.
  3. Create a new Windows Application in Visual Basic .NET. Form1 is created by default.
  4. Make sure that your project contains a reference to the System.Data namespace, and add a reference to it if it does not.
  5. Drag a Button control to Form1, and change its Name property to btnTest.
  6. Use the Imports statement on the System, System.Data, and System.Data.OleDb namespaces so that you are not required to qualify declarations in those namespaces later in your code.
    Imports System
    Imports System.Data
    Imports System.Data.OleDb
    					
  7. Copy and paste the following code in the code window after the "Windows Form Designer generated code" section:
    Private Sub btnTest_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnTest.Click
        Dim sConnectionString As String _
            = "Provider=MSDAORA.1;User ID=scott;password=tiger;"_
              "Data Source=myOracleServer;Persist Security Info=False"
        Dim mySelectQuery As String _
            = "SELECT * FROM TestTable where c1 LIKE ?"
        Dim myConnection As New OleDbConnection(sConnectionString)
        Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
       
        'Set the parameter value.
        myCommand.Parameters.Add("@p1", OleDbType.Char, 5).Value = "Test%"
        
        'Open connection to Oracle database.
        myConnection.Open()
        
        'Populate the DataReader.
        Dim myReader As OleDbDataReader = myCommand.ExecuteReader()
        Dim RecordCount as Integer
        Try
            While myReader.Read()
                RecordCount = RecordCount + 1
                MessageBox.Show(myReader.GetString(0).ToString())
            End While
            If RecordCount = 0 then
                MessageBox.Show("No data returned")
            Else
                MessageBox.Show("Number of records returned: " & RecordCount)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        Finally
            
           'Close all objects.
            myReader.Close()
            myConnection.Close()
        End Try
    End Sub
    					
  8. Save your project.
  9. On the Debug menu, click Start to run your project.
  10. Click the button to display the data.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
176936  (http://kbalertz.com/Feedback.aspx?kbNumber=176936/EN-US/ ) INFO: Visual Basic Accessing an Oracle Database Using ADO
For more information about ADO.NET objects and syntax, see the following topic in the Microsoft .NET Framework Software Development Kit (SDK) documentation or MSDN Online:
Accessing Data with ADO.NET
http://msdn2.microsoft.com/en-us/library/e80y5yhx(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/e80y5yhx(vs.71).aspx)
For more general information about ADO.NET or Visual Basic .NET, refer to the following MSDN newsgroups:
microsoft.public.dotnet.framework.adonet (http://msdn.microsoft.com/newsgroups/default.aspx?query=microsoft.public.dotnet.languages.vb&dg=&cat=en-us-msdn&lang=en&cr=US&pt=&catlist=774F24A2-F71F-425F-AC2B-DC48AB0DA5C9&dglist=&ptlist=&exp=&sloc=en-us)

microsoft.public.dotnet.languages.vb (http://go.microsoft.com/fwlink/?linkid=5820)

APPLIES TO
  • Microsoft ADO.NET 1.1
  • Microsoft ADO.NET 1.0
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
Keywords: 
kbhowtomaster kbsystemdata KB308071
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please