.NET
  Home arrow .NET arrow Page 4 - .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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 12
    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


    .NET Stored Procedure: Reading a Text File into an Oracle Table - How to read all the lines from the text file


    (Page 4 of 5 )

    In the previous sections, we have just seen how to work with only the first line from the text file.  Nobody will be happy to work with only one line.  Now, I shall expand the same program to meet our requirements of reading several lines (or all lines) at a time. 

    Instead of modifying the above code, I planned to create a new method named “ReadAll” (stands for “read all lines” from the text file).  The code would be as follows:

    Public Shared Sub readAllLines()
            Dim sr As New StreamReader("c:\sample.txt")
     
            Dim l As String = sr.ReadLine
            Dim arContent As New ArrayList
            While Not l Is Nothing
                arContent.Add(l)
                l = sr.ReadLine
            End While
            sr.Close()
     
           
            Dim conn As New OracleConnection("context
    connection=true")
            For Each l In arContent
                Dim cmd As New OracleCommand
                cmd.Connection = conn
                cmd.CommandText = "insert into scott.sampletable
    values ('" & l & "')"
                conn.Open()
                cmd.ExecuteNonQuery()
                cmd.Dispose()
                conn.Close()
            Next
        End Sub

    Let us go part by part.  Let us consider the following code first:

            Dim l As String = sr.ReadLine
            Dim arContent As New ArrayList
            While Not l Is Nothing
                arContent.Add(l)
                l = sr.ReadLine
            End While
            sr.Close()

    The above code fragment is the heart of the method, as it reads all the lines using a simple loop and finally places all those lines into an array list called “arContent”.  The next code fragment will deal with transferring from “arContent” to the table:

            Dim conn As New OracleConnection("context
    connection=true")
            For Each l In arContent
                Dim cmd As New OracleCommand
                cmd.Connection = conn
                cmd.CommandText = "insert into scott.sampletable
    values ('" & l & "')"
                conn.Open()
                cmd.ExecuteNonQuery()
                cmd.Dispose()
                conn.Close()
            Next

    We used a new loop to read every line from the array list “arContent” and used the “OracleCommand” object to work with the INSERT command. 

    More .NET Articles
    More By Jagadish Chaterjee


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

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek