473,382 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

IMPORT TEXT/EXCEL FILE INTO ORCALE TABLE

Hi,
I am pasting the code to import data from Text/Excel files into Database(Oracle ) Table...
I think some one needs this .. they can use.. it...
=======================
Dim dsDB As New DataSet
Dim daDB As New OracleDataAdapter
Dim cmdDB As OracleCommand = New OracleCommand
Dim strRow As String
Dim sqlArr() As String 'Array which stores all queries of all records to be executed as a whole to database
Dim RetVal As Long = 0

'For Soucrec file
Dim DSSRC As New DataSet
Dim SourceFolder As String
Dim SRCConn As String

SourceFolder = G_SelectedFile.Substring(0, G_SelectedFile.LastIndexOf("\"))
If SourceFolder.Length = 2 Then 'if the file is there in c: or d: like that then we need to add to c:\ like that
SourceFolder = SourceFolder & "/"
End If
SRCConn = "MaxBufferSize=2048;FIL=excel 8.0;DSN=" & TBDSNName.Text.ToString.Trim() & ";PageTimeout=5;DefaultDir=C:\;DBQ=" & G_SelectedFile & ";DriverId=790"
Dim SRCDA As New OdbcDataAdapter("SELECT * FROM " & "[" & TxtSheet.Text & "$]", SRCConn)

Try
SRCDA.Fill(DSSRC, "Table")
Catch e As Exception
MessageBox.Show(e.Message.ToString(), G_MsgStr)
Exit Sub
End Try

'Destination DB Connections
If Cn.State <> ConnectionState.Open Then
If connect("internal", G_UID, G_Pwd, G_TnsName) = False Then
Exit Sub
End If
End If

cmdDB.CommandType = CommandType.Text
cmdDB.CommandText = "select * from " & CBOTNames.SelectedValue & " where 1>2" ' G_SelectedFile.Substring(G_SelectedFile.LastIndexO f("\") + 1).ToString().Trim()
cmdDB.Connection = Cn
daDB.SelectCommand = cmdDB

Try
daDB.Fill(dsDB, "Table")
daDB.AcceptChangesDuringFill = True
Catch ex As Exception
MessageBox.Show("Invalid or Unable to open the table" & ex.Message)
Exit Sub
End Try
dsDB.Merge(DSSRC, False, MissingSchemaAction.Ignore)
ReDim sqlArr(0) 'Initialises with 0 first
For RowiDx As Integer = 0 To dsDB.Tables(0).Rows.Count - 1
strRow = ""
For ColIdx As Integer = 0 To dsDB.Tables(0).Columns.Count - 1
If ((dsDB.Tables("Table").Rows(RowiDx)(ColIdx).GetTyp e.ToString() = "System.Decimal") Or (dsDB.Tables("Table").Rows(RowiDx)(ColIdx).GetType .ToString() = "System.Decimal")) Then
strRow = strRow & dsDB.Tables("Table").Rows(RowiDx)(ColIdx) & ", "
Else
strRow = strRow & "'" & dsDB.Tables("Table").Rows(RowiDx)(ColIdx) & "' , "
End If
Next
strRow = strRow.Remove(strRow.LastIndexOf(",") - 1, 2)
strRow = " insert into " & CBOTNames.SelectedValue & " values ( " & strRow & ")"
ReDim Preserve sqlArr(UBound(sqlArr) + 1)
sqlArr(UBound(sqlArr)) = strRow
Next

If UBound(sqlArr) > 0 Then RetVal = ExecuteDML(sqlArr)
If RetVal > 0 Then
MessageBox.Show("Data Has been transfered successfully", G_MsgStr)
Else
MessageBox.Show("Unable to Transfer " & G_SelectedFile & " records into " & CBOTNames.SelectedValue & "")
End If

End Sub

Public Function ExecuteDML(ByVal sql() As String) As Long
Dim RecordsAffected As Long
Dim DMlIdx As Long
ExecuteDML = 0
Dim cmd As New OracleCommand
Try
If Cn.State <> ConnectionState.Open Then
If connect("internal", G_UID, G_Pwd, G_TnsName) = False Then
Exit Function
End If
End If
cmd.Connection = Cn
TotSuccessRecords = 0
For DMlIdx = 1 To UBound(sql) 'starting of array is 1
TotSuccessRecords += 1
cmd.CommandText = sql(DMlIdx)
RecordsAffected = cmd.ExecuteNonQuery()
Next
ExecuteDML = RecordsAffected
Exit Function
Catch ex As Exception
cmd.Dispose()
End Try
End Function

--------------------------------
From: ramnaresh_t yadav

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>NJb2N1VLyEaEVamFsttr3A==</Id>
Nov 20 '05 #1
0 1650

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Richard Holliingsworth | last post by:
Hello: Thanks for your quick response. I'm trying to import a new Excel file into an A2K table and it's truncating the data. One of the Excel columns is a text field that can be up to 2000...
5
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
3
by: deko | last post by:
I've been trying to use the Access Import Wizard to expedite importing data into my mdb. The nice thing about the wizard is that I can import from different file formats - txt, xls, even Outlook -...
3
by: ninrulz | last post by:
I will try to explain my situation. I know that it is hard to offers solutions without fully understanding what people would like to achieve. I receive 2 csv files every month. The csv files...
2
by: KingoftheKings | last post by:
I'm new here. I want a help with VB codes that will import text or excel files from a specified directory in to an existing or new Access table. I have written some codes, but when I click the...
4
by: Earl Anderson | last post by:
I guess I missed the boat on the logic for this one. Immediately upon hitting "Import" in an attempt to import an Excel file containing 7 columns of 'txt' formatted data into AXP, I got a "Type...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
5
geolemon
by: geolemon | last post by:
Import text wizard says: I'm banging my head on this one, here's why: I've been importing files using this process and data format, with success! I created a temporary table in Access to...
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.