.NET
  Home arrow .NET arrow Page 3 - .NET Stored Procedures: Autogenerating INS...
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 Procedures: Autogenerating INSERT Statements for rows in Oracle Tables
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2005-12-20

    Table of Contents:
  • .NET Stored Procedures: Autogenerating INSERT Statements for rows in Oracle Tables
  • Developing Oracle based .NET CLR stored procedure using Visual Studio.NET
  • Understanding the .NET CLR Stored Procedure
  • Understanding the .NET CLR Stored Procedure - continued
  • Deploying and testing the Oracle based .NET CLR stored procedure using Visual Studio.NET

  • 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 Procedures: Autogenerating INSERT Statements for rows in Oracle Tables - Understanding the .NET CLR Stored Procedure


    (Page 3 of 5 )

    Before deploying the .NET stored procedure, let us go through some of the details of the previous program.  You must have observed “imports System.IO” at the top.  This is primarily required to deal with any operations on the file system.  You can completely control the file system (make sure that you have the permissions) just by using “System.IO”.  As I am dealing with text files here, I need to make use of it at the moment.

    Let us go through the program part by part:

         Public Shared Sub GenerateInsertCommands(ByVal sqlSELECT As String, ByVal TableName As String, ByVal FilePath As String)

    The above statement is the main declaration for the stored procedure.  It has three parameters (arguments):

    • sqlSELECT
    • TableName
    • FilePath

    “sqlSELECT” is mainly used to pass your own “SELECT” statement to retrieve whatever rows you want.  Any SELECT statement is acceptable, including JOINS, SUBQUERIES, and so on.  All of the rows expected from the SELECT statement are to be turned to INSERT statements.

    Everyone knows that the INSERT needs to be specified with a table name.  The second parameter “TableName” is required to provide the table name for the INSERT statement, from which it needs to be generated.

    Finally, we need to place all the INSERT statements in a particular text file.  The final parameter “FilePath” is nothing but the file name of that text file along with the required path.  But you should also make sure that you have permission to use that path, to generate/create files.

    Proceeding further, we have the following:

             Dim conn As New OracleConnection("context connection=true")
            Dim da As New OracleDataAdapter(sqlSELECT, conn)
            Dim cb As OracleCommandBuilder = New OracleCommandBuilder(da)
            Dim ds As New DataSet
            da.Fill(ds, "temp")
            da.Dispose()
            conn.Close()

    The above code fragment just connects to Oracle (with no external connection; it uses the internal context), executes the SELECT statement (specified through “sqlSELECT”) and fetches all rows in to the dataset “ds”.  Once we get a local copy of all the rows, we can close the connection and release the resources.

    We shall discuss the heart of the .NET-stored procedure in the next section.

    More .NET Articles
    More By Jagadish Chaterjee


       · Hello guys, this is my second article on .NET CLR stored procedures in Oracle. Enjoy...
     

    .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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek