Results 1 to 5 of 5

Import .csv to DB2 automatically

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Import .csv to DB2 automatically

    Hello everyone,

    I have a .csv file that needs to be imported into a IBM DB2 table. I can import .csv data manually, but I want to do It automatically with VBA, If possible.

    I have found some VBA code that might work, but cannot set It right, or It isn't what I think It is.

    Code:

    Option Explicit
    
    Dim DBCONSRT, QRYSTR ans As String
    Dim DBCON, DBRS  As Object
    
    Dim excel_app As Object
    
    Private Sub CommandButton1_Click()
        Set excel_app = CreateObject("Excel.Application")
        DBCONSRT = "Driver={IBM DB2 ODBC DRIVER};Database=<OFFROAD>;hostname=<localhost>;port=<50000;protocol=TCPIP; uid=<db2admin>; pwd=<sample123>"
        'CHANGE THE BELOW QUERY STRING ACCORDIGN TO YOUR NEED
        QRYSTR = "db2 import from C:\Users\db2admin.Luka-PC\Documents\auth.csv of del insert into db2admin.razpored"
        Set DBCON = CreateObject("ADODB.Connection")
        DBCON.ConnectionString = DBCONSRT
        DBCON.Open
        'BELOW CODE USED TO GET THE DATABASE CONECTION AND EXECUTE THE QUERY CHANGE ACCORDIGN TO YOUR NEED
        Set DBRS = CreateObject("ADODB.Recordset")
        With DBRS
            .Source = QRYSTR
        Set .ActiveConnection = DBCON
            .Open
        End With
        
    End Sub
    When I run the code I get an error "[IBM][CLI driver] SQL1337N The service "<50000>" was not found" !

    I don't know about OLE DB or ODBC driver - as instructed, I should have one installed on local machine, but can't find anywhere how to download It.

    Also, when I use Data>Import External data>Import Data tool in Excel, I can connect to DB2 database directly from Excel, so maybe ODBC driver allready installed ??

    My version of DB2 is Express-C 10.5, and Excel 2003.

    I'm not sure either If red coloured line of code is basically an SQL command or db2cmd command (which I need exactly as written - I need to import .csv into specific table called "razpored")


    I know this is probably a tough question, but can somebody please help me ?
    Last edited by Lukael; 10-04-2014 at 12:53 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I need a Macro to automatically import web pages
    By Bret1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-24-2013, 05:56 PM
  2. Automatically import XML into excel using vba
    By JCampos081 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-04-2012, 11:04 PM
  3. Import Automatically Pictures
    By leturc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-21-2012, 06:11 AM
  4. automatically import a file
    By boomshank in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2009, 09:43 AM
  5. can I automatically import .csv file?
    By jaspittman in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-11-2008, 02:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1