Connecting to sql server is easy in QTP. In below example, we have connected to sql server.
The name of database is empdb. We have created a DSN called sqlserver.
'fetch data from database
Set db = createobject("ADODB.Connection")
'open the connection to empdb database.
db.Open "DSN=sqlserver;Database=empdb"
'create record set object
Set rst = createobject("ADODB.Recordset")
'fire the query
rst.Open "select * from emp", db,3
id = rst.RecordCount
For i=0 to id-1
'read data from table
print rst.fields(0) & rst.fields(1)
rst.Movenext
Next
The name of database is empdb. We have created a DSN called sqlserver.
'fetch data from database
Set db = createobject("ADODB.Connection")
'open the connection to empdb database.
db.Open "DSN=sqlserver;Database=empdb"
'create record set object
Set rst = createobject("ADODB.Recordset")
'fire the query
rst.Open "select * from emp", db,3
id = rst.RecordCount
For i=0 to id-1
'read data from table
print rst.fields(0) & rst.fields(1)
rst.Movenext
Next
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts. You can write to me at reply2sagar@gmail.com
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs