How to fetch data from database table and export to an excel sheet ?
I have tried this way to export data from a database table to store in an excel sheet, but it is only storing the last record of the received records. Can anyone help me.
Set objDB = CreateObject("ADODB.Connection")
objDB.ConnectionString = "DSN=mysql_qtp"
objDB.Open
If objDB.state=1 Then
msgbox("Connection Is Establsihed")
else
msgbox("Connection is not opened")
exittest
End If
sql_query = "select zipcode, cityName from ZipMapRegion limit 3"
Set objResults = objDB.Execute(sql_query )
Set s=datatable.GetSheet ("Global")
Set zipcode=s.addparameter("cityName"," ")
Set cityName=s.addparameter("cityName"," ")
Do Until objResults.EOF
DataTable.SetNextRow
zipcode.value = objResults("zipcode")
cityName.value = objResults("cityName")
msgbox zipcode & " " & " "& cityName
objResults.MoveNext
Loop
DataTable.ExportSheet "C:Tempzips.xls" , 1
msgbox "The file is saved in C:Tempzips.xls"
objResults.Close
objDB.Close
Questions by eswarqa answers by eswarqa
Showing Answers 1 - 1 of 1 Answers
Related Answered Questions
Related Open Questions
How to fetch data from database table and export to an excel sheet ?
Set objDB = CreateObject("ADODB.Connection")
objDB.ConnectionString = "DSN=mysql_qtp"
objDB.Open
If objDB.state=1 Then
msgbox("Connection Is Establsihed")
else
msgbox("Connection is not opened")
exittest
End If
sql_query = "select zipcode, cityName from ZipMapRegion limit 3"
Set objResults = objDB.Execute(sql_query )
Set s=datatable.GetSheet ("Global")
Set zipcode=s.addparameter("cityName"," ")
Set cityName=s.addparameter("cityName"," ")
Do Until objResults.EOF
DataTable.SetNextRow
zipcode.value = objResults("zipcode")
cityName.value = objResults("cityName")
msgbox zipcode & " " & " "& cityName
objResults.MoveNext
Loop
DataTable.ExportSheet "C:Tempzips.xls" , 1
msgbox "The file is saved in C:Tempzips.xls"
objResults.Close
objDB.Close
Profile Answers by eswarqa Questions by eswarqa
Questions by eswarqa answers by eswarqa
Related Answered Questions
Related Open Questions