.NET
  Home arrow .NET arrow .NET Stored Procedure: Reading a Text File...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

.NET Stored Procedure: Reading a Text File into an Oracle Table
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2005-12-27

    Table of Contents:
  • .NET Stored Procedure: Reading a Text File into an Oracle Table
  • Deploying the Oracle based .NET CLR stored procedure using Visual Studio.NET
  • Testing the Oracle-based .NET CLR stored procedure
  • How to read all the lines from the text file
  • How to read all the lines from the text file – in a better and more efficient way

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    .NET Stored Procedure: Reading a Text File into an Oracle Table


    (Page 1 of 5 )

    In this article, I shall introduce you to developing a .NET based CLR stored procedure, which can read a simple text file and transfer that information into an Oracle database using Visual Studio.NET.
    A downloadable file for this article is available here.

    Getting prepared before developing .NET CLR stored procedure

    I already introduced .NET based stored procedures in an Oracle database at “.NET CLR stored procedures within Oracle database: Another breaking
    revolution
    ." If you are very new to this concept, I suggest you go through that article before proceeding further.

    Before proceeding further with this article, make sure that all of the following software is properly installed and configured on your system:

    As we are trying to read a text file from a file system, we first need to create a simple text file (in this article, I named the file “sample.txt”) with a few lines.  The most important issue to remember is that the file needs to reside at the Oracle database server and not at the client (or with required shared permissions, if on the network drive).

    The next step would be to create a table in the Oracle database to hold all those “strings” of lines in a single column.  Try the following command to create a new table in Oracle as follows:

     CREATE TABLE SAMPLETABLE
    (
          DESCRIPTION       VARCHAR2(300)
    )

    As this is a demonstration, I suggest you create the above table “SAMPLETABLE” within the SCOTT schema.  My entire source code focuses on the “SCOTT” schema.  I request that you make necessary changes to the source code, if you create the table in a different schema.

    I assume that you are already connected to the Oracle database using “Oracle Explorer” using Visual Studio.NET 2003.  If you are not quite familiar with “Oracle Explorer,” I request that you refer to my article at “.NET CLR stored procedures within Oracle database: Another breaking revolution," linked above.

    Now we shall proceed to the next section, which deals with creating the stored procedure.

    Developing Oracle based .NET CLR stored procedure using Visual Studio.NET

    Once you complete all of the steps in the previous section, proceed with the following steps to develop a .NET CLR based stored procedure using Visual Studio.NET.

    • Go to File -> New -> Project.
    • Within the “New Project” window, select “Visual Basic Projects” as Project Type “Oracle Project” as the template, Name as “Sample1” and click “OK”  (Fig 1).

    • Modify the code as follows:
    Imports Oracle.DataAccess.Client
    Imports Oracle.DataAccess.Types
    Imports System.IO
     
    Public Class Class1
     
        Public Shared Sub read()
            Dim sr As New StreamReader("c:\sample.txt")
            Dim l As String = sr.ReadLine
            sr.Close()
     
            Dim conn As New OracleConnection("context
    connection=true")
            Dim cmd As New OracleCommand
            cmd.Connection = conn
            cmd.CommandText = "insert into scott.sampletable values
    ('" & l & "')"
            conn.Open()
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            conn.Close()
     
        End Sub
    End Class
    • Finally build the application

    Before deploying the stored procedure, let us go through some of its details.  You must have observed “imports System.IO” at the top.  This is primarily required to deal with the file system (and also other input/output operations).  I created an object based on the “StreamReader” class to open and read the file “sample.txt”.  At the moment, I read only one line from the file (the first line only) and I am trying to insert it using the “OracleCommand” object. 

    More .NET Articles
    More By Jagadish Chaterjee


       · Hello guys, another article contributed towards .NET CLR stored procedure in Oracle....
     

    .NET ARTICLES

    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...
    - Coding an AjaxPro.NET Based Search Engine fo...
    - Building an AjaxPro.NET Based Search Engine ...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway