Forum Discussion
2 Replies
Sort By
- Krishna_KumarContributor
Hi vikassardesai ,
please reffer the below code and modify as required.
Function GetContentFromDB (strFileName, strSQLStatement) Dim objAdCon, objAdRs Set objAdCon = CreateObject(“ADODB.Connection”) objAdCon.Open “DRIVER={Microsoft Excel Driver (*.xls)};DBQ=”&strFileName & “;Readonly=True” If Err <> 0 Then Log.Error(“Error has occured while Creating Connection: ”) Set obj_UDF_getRecordset = Nothing Exit Function End If Set objAdRs = CreateObject(“ADODB.Recordset”) objAdRs.CursorLocation=3 objAdRs.Open strSQLStatement, objAdCon, 1, 3 While objAdRs.EOF=false For i=0 to objAdRs.Fields.count Log.Message(objAdRs.fields(i)) Next objAdRs.moveNext Wend If Err<>0 Then Log.Error(“Error occured”) Set obj_UDF_getRecordset = Nothing Exit Function End If Set objAdRs.ActiveConnection = Nothing objAdCon.Close Set objAdCon = Nothing End Function
above function will take two parameters (filename with the path and query)
below is the sample call method
Set rsSampleRS= GetContentsFromDB(“C:\Documents and Settings\mohank\Desktop\Login.csv”, “Select [UserName] from [sheet1]”)
please let me know if its working or not
Kind Regards,
Sathish Kumar K
- tristaanogreEsteemed Contributor
The code provided is a lot more complicated than it ahs to be. Refer to https://support.smartbear.com/testcomplete/docs/reference/program-objects/ddt/csvdriver.html
Sample code provided in the article for iterating through records in the CSV file. Within the while loop is where you would assign your values to the array. There's no need, using DDT, to create ADO objects and run queries and so on.
Related Content
- 13 years agojyothi_priya
- 2 years agoShahZaib
- 8 years agoWestManBruce
Recent Discussions
- 3 hours agoSvetaG