Data taking out from Database and write it back to Excel
Hi ,
Can some one help me in the below feature?
1. Take data out of the database & Save it in Excel file via Test Complete
2. Take data out of an Excel file and save it to the database via Test Complete
I could able to read it from Excel, but dont know how to write it / insert into Database table
It will be greatful if some body has code.
I have a code for reading it from Excel DB & displaying.
Dim sAutomationPath
sAutomationPath
sAutomationPath = "D:\Database\"
Function ConnectDB
ConnectDB
Set AConnection = ADO.CreateADOConnection
Dim sConnectionString
sConnectionString = _
"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" & _
"DriverId=790;" & _
"Dbq=" + sAutomationPath + "Database_Test.xlsx;" & _
"DefaultDir=" + sAutomationPath
AConnection.ConnectionString = sConnectionString
AConnection.LoginPrompt = False
AConnection.Open
Set ConnectDB = AConnection
End Function
'********************************************************************
Function FetchDB (sTableName, sSheetName)
FetchDB (sTableName, sSheetName)
Dim iIndex
'Get ADO Connection Object
Set AConnection = ConnectDB ()
Set Driver = DDT.ExcelDriver(sAutomationPath + "Database_Test.xlsx", sSheetName,true)
MsgBox(sAutomationPath)
Set RecSet = AConnection.Execute_("SELECT * FROM "+ sTableName)
Set objDict = CreateObject("Scripting.Dictionary")
RecSet.MoveFirst
While Not RecSet.EOF
for iIndex = 1 to Driver.ColumnCount-1
objDict.Add (Driver.ColumnName(iIndex)), RecSet.Fields(Driver.ColumnName(iIndex)).Value
Next
RecSet.MoveNext
WEnd
Call DDT.CloseDriver(Driver.Name)
Set FetchDB = objDict
End Function
Regards,
Mohanraj R
ConnectDB FetchDB (sTableName, sSheetName)