NOTICE: Our Community is moving. Get more information. Updated information on a New Login Process
Data can be read from Excel spreadsheets using the SilkTest DB_Tester functions. The following is a sample piece of code that will illustrate. This code uses simple SQL to read from Excel, the user can write specific SQL statements to perform more complex data retrieval.
[-] testcase Database_example () [ ] //To tell DBTester what DB to connect to [ ] STRING sConnectString = "DSN=Test;DBQ=C:\example.xls" [ ] [ ] //Connect to database and keep a reference to it [ ] HANDLE hDB = DB_Connect (sConnectString) [ ] [ ] //SQL Command to be carried out on DB [ ] STRING sSQL = "SELECT * FROM `Sheet1$` `Sheet1$`" [ ] [ ] //Execute the SQL Statement and keep a reference to the resulting table [ ] HANDLE hSQL = DB_ExecuteSQL (hDB, sSQL) [ ] [ ] //Variable to hold any data retreived from the database [ ] LIST OF ANYTYPE laData [ ] [ ] //Query result table and copy data into variable [+] while (DB_FetchNext(hSQL, laData)) [ ] //Print one record at a time to a results file [ ] Print (laData) [ ] [ ] //Clean Up and Disconnect [ ] DB_FinishSQL (hSQL) [ ] DB_Disconnect (hDB)