Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

I need to import a text file data to Oracle using ADO.NET,

 

First I create a DataSet from Oracle table ,TEST_A,

   Private Sub OraOLEDB()

       Dim OraConn As OleDbConnection = New OleDbConnection("Provider= MSDAORA.1;" & _
                                                            "User ID = XXXX;" & _
                                                            "Password= XXXX;" & _
                                                            "Data Source=XXXX")
       Try
           OraConn.Open()
           Dim OraDataAdpt As New OleDbDataAdapter("SELECT * FROM TEST_A", OraConn)
           Dim OraDataSet As New DataSet("SA")
           Dim OraDataTable As New DataTable("TEST_A")
           OraDataAdpt.Fill(OraDataSet, "TEST_A")

       Catch ex As Exception
           MessageBox.Show(Err.Description)
           'MessageBox.Show("Failed to connect to data source")
       Finally
           If OraConn.State = ConnectionState.Open Then
               OraConn.Close()
           End If
           OraConn.Dispose()
       End Try

   End Sub

 

I wrote some code to split data in text file and save to DataSet:

       Dim FileStream As StreamReader
       Dim sLine As String = ""
       Dim TextDelimiter As String = Chr(9) '{TAB}

       Dim Splitout() As String
       Dim I As Integer

       FileStream = File.OpenText("c:\test.txt")
       Do
           sLine = FileStream.ReadLine()
           If Not sLine Is Nothing Then
               Splitout = Split(sLine, TextDelimiter)
               For I = 0 To UBound(Splitout)
                   'Save To DataSet
               Next I
           End If
       Loop Until sLine Is Nothing
       FileStream.Close()

 

After done, I need to insert all data to Oracle table,but don't know how to do.

Can anybody help me with this ?

 

Or maybe you have better solution with the import feature is welcome.

 

Cheers,

 

Stanley

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...