Powered by: Dharamveer Saxena

Monday, November 2, 2009

TestComplete : Connect to SQL database and fetch data by executing query



' Sample Code to Connect to database in Test Complete
' Database connection using Testcomplete


Sub main

Set AConnection = ADO.CreateADOConnection

AConnection.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=DG18\SQLEXPRESS"

AConnection.LoginPrompt = False ' Suppress the login dialog box
AConnection.Open

Set RecSet = AConnection.Execute_("SELECT * FROM holding") ' Execute a simple query
RecSet.MoveFirst
While Not RecSet.EOF
Log.Message RecSet.Fields("Script").Value
RecSet.MoveNext
Wend
AConnection.Close
End sub



6 comments:

  1. How to get count of a particular control say,textbox in a form?

    ReplyDelete
  2. for that you can loop through the child controls on the form and if child control type is textbox then increase the textbox_control_counter with 1
    the code may be like:

    counter = 0
    for i = 0 to form.childcount
    if form.child(i).type = "Textbox" then
    counter = counter + 1
    end if
    next
    msgbox(counter)

    ReplyDelete
  3. Hey Dharamveer, can you give me your mail address ?

    ReplyDelete
  4. Hi "v", I have shared my mail ID.... you can get it by viewing my profile...

    (Goto "view my complete Profile")

    ReplyDelete
  5. Hi

    I have more than one type of DB , like CSV, Excel, MSSQL etc.

    Based on the type of database that DB should be logged in that is my requirement.
    So do I have to write separate connection functions for each sort of data?

    ReplyDelete
  6. Execute_-->this doesnt work for me.

    ReplyDelete