Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / May 2006

Tip: Looking for answers? Try searching our database.

Loading data from Excel to Oracle

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dr Sanjay - 24 May 2006 16:19 GMT
Hi All,
I would like to load an Excel spreadsheet directly into a single table in
Oracle. Both the spreadsheet and the table have the same ordering of columns
and have compatable data.

I am aware that a way to achieve this would be to convert the .xls file into
a .csv file and then use sql loader. However, I am interested in doing this
in a quicker/easier way directly from Excel, eg. by adding in some
functionality and clicking on a new button for loading into the database.

We are all able to read from a database in Excel by importing external data.
Surely there is a way to change that data and write it back to the database
from Excel?
kind regards
galimi - 26 May 2006 15:06 GMT
Dr. Sanjay,

Following is some code that should help:

Public Function LoadSheetToDB(sSheetName As String, sTableName As String) As
Boolean
   
   On Error GoTo Err_LoadSheetToDB
   
   Dim rs          As New ADODB.Recordset
   Dim lStartRow   As Long
   Dim lEndRow     As Long
   Dim lStartCol   As Long
   Dim lEndCol     As Long
   
   Dim iRowIndex    As Long
   Dim iColIndex    As Long
   
   sShtName = sSheetName
   
   With Sheets(sSheetName)
       lStartCol = 1
       lEndCol = .Range("Header").Columns.Count
       lStartRow = 1
       lEndRow = .Range("Data").Rows.Count
   End With
   
 
   rs.Open "SELECT * from " & sTableName, GetDBConnection, adOpenStatic,
adLockOptimistic
   'MsgBox rs("cusip_id")
   
   For iRowIndex = lStartRow To lEndRow
       rs.AddNew
       For iColIndex = lStartCol To lEndCol
           With Sheets(sSheetName)
               Debug.Print .Range("Header").Cells(1, iColIndex).Value
               rs(.Range("Header").Cells(1, iColIndex).Value) =
.Range("Data").Cells(iRowIndex, iColIndex).Value
           End With
       Next
       
       rs.Update
   Next
   rs.Close
   LoadSheetToDB = True
   
Exit_LoadSheetToDB:
   Set rs = Nothing
   Exit Function
   
Err_LoadSheetToDB:
   LoadSheetToDB = False
   modErrorFunctions.WritetoErrorLogADOErrors "LoadSheetToDB",
GetDBConnection.Errors, MOD_NAME
   Resume Exit_LoadSheetToDB
End Function

The key elements in this are the .AddNew & .Update methods.  Everything else
will have to be modified to fit your circumstance.
Signature

http://HelpExcel.com
1-888-INGENIO
1-888-464-3646
x0197758

> Hi All,
> I would like to load an Excel spreadsheet directly into a single table in
[quoted text clipped - 10 lines]
> from Excel?
> kind regards
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.