Quick test professional

QTP Tips QTP codes QTP Faqs and more

update data in a database

To update information is entered into the database at runtime, you will need to add code to your script which will open a connection to the database, update the database, then close the connection. Here are the steps to do this (an example follows). 1. Create an “ADODB.Connection” object (the database object).
2. Set the connection string for the database object.
3. Open the connection to the database.
4. Execute a SQL statement.
5. Close the database connection.

Example:Set cnBiblio = CreateObject(“ADODB.Connection”)

‘ Set the connection string and open the connection
cnBiblio.ConnectionString = “DSN=QT_Flight32;DBQ=C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight32.mdb;Driver=C:\WINDOWS\System32\odbcjt32.dll;DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;”
‘ Open the connection to the database

‘ or use this method if a DSN entry was created.
‘ cnBiblio.Open(“DSN=Flight32”)

‘ Execute the update query (SQL statement)
cnBiblio.Execute “Update Orders SET Orders.Customer_Name = ‘John Doe’ where Orders.Order_Number = 1”

‘ Close the connection.
cnBiblio.Close Note: The syntax of the Update SQL statement may vary depending on the database in use. The example above uses the sample Flight32 MS Access database.

  Source: Mercury Forum’s KB articles


February 14, 2008 - Posted by | Update data in a database | , , , , , , , , ,


  1. Hello Dear,
    It really awesome website but at this time I need your help acctullay I wanted to get dat from webtable and import in excel or datatable do you have knowledge or solution or sample code to resolve this issue.
    I appreciate you help

    Comment by Kamran | July 10, 2009 | Reply

  2. Dear Mohan,

    Very good source of qtp knowledge you have created for people at beginners level or even at matured level. Keepup the good work. Where do you work and where are you located. Can I have your contact id?



    Comment by Dr. Narinder Gupta | July 30, 2009 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: