11-01-2010, 05:44 PM
Hi,
See below code, it works fine.
See below code, it works fine.
Code:
' Connect to the flight 32 database
Set Conn = CreateObject("ADODB.Connection")
Set Rs = CreateObject("ADODB.recordset")
'Conn.Open("DSN=Flight32")
Conn.Open("DSN=QT_Flight32")
'Specify the query
sql = "Select * from Orders"
'Set the recordset cursor type
Rs.CursorType = 1 'set to a Keyset cursor type
'Execute the Query
Rs.Open sql,Conn
'Get the no records returned by query
Recordcount = Rs.RecordCount
'Adding a column to datatable
DataTable.GlobalSheet.AddParameter "Customer_Name",""
'Get the values from the customer_Name column
While(NOT Rs.EOF)
'Msgbox Rs.Fields("Customer_Name")
For i=1 to Recordcount
DataTable.SetCurrentRow(i)
'Writing the data to the datatable
DataTable("Customer_Name",DtGlobalSheet) = Rs.Fields("Customer_Name")
Rs.MoveNext
Next
wend
'Exporting the Datatable to C:\DatabaseExample.xls
DataTable.Export "C:\DatabaseExample.xls"
'close the database connection
Conn.close
Set Conn = Nothing
Set Rs = Nothing