Forum Discussion

Manoj8690's avatar
Manoj8690
New Contributor
5 years ago
Solved

db2/as400 load data in excel sheet

Hi Folks,

Can anyone help me to set connection with DB2/AS400 data base and load data in excel sheet.

Thanks,

Manoj

 

  • Thanks Everyone for your suggestion!!

    Now I am able to fetch details from Database with below code.

    But, could not able to store in excel... Can anyone help me for copy/save data from recordset to excel.

     

    Sub TestADO
    Dim Conn, Rs , strSql
    Const adOpenStatic = 0
    Const adLockOptimistic = -1
    Const adCmdText = "&H0001"

    Set Conn = CreateObject("ADODB.Connection")
    strSql = "SELECT * from TableName LIMIT 20"

    Conn.ConnectionString = "Provider=MSDASQL.1;" & "Persist Security Info=False;" & "User ID=NA;" & "Extended Properties= " & "DSN=NA;SYSTEM=NA;UID=NA;DBQ=NA;DFTPKGLIB=NA;LANGUAGEID=ENU;PKG=NA/DEFAULT(IBM),2,0,1,0,512;QRYSTGLMT=-1;"

    Conn.Open
    ' Create a recordset
    Set Rs = CreateObject("ADODB.Recordset")
    ' Open the recordset and get the Orders table from the OrdersDB database

    'Rs.Open strSql, Conn, 3, 1, 2 ' adOpenStatic, adLockReadOnly, adCmdTable

    Rs.Open strSql, Conn, adOpenStatic, adLockReadOnly, adCmdText

    Log.AppendFolder "Customer names"
    Rs.MoveFirst
    While Not Rs.EOF
    Log.Message Rs.Fields.Item("NA").Value
    Rs.MoveNext
    WEnd
    Rs.Close
    Conn.Close
    End Sub

5 Replies