Hi,
Any one tell me How to Import the data from MS-Access in QTP?
Printable View
Hi,
Any one tell me How to Import the data from MS-Access in QTP?
Hi Ramya,
You can use the same createObject method to export data from MS Access as well. Here is the code guideline for the following -
dim oConn
dim sRec
set oConn = createObject("ADODB.Connection")
oConn.open "Provider = Microsoft.Jet.OLEDB.4.0;DataSource = <
NOTE : Incase authentication is required as in case of SQL Server, we would have to pass UserID and Pwd as well.
set sRec = createObject("ADODB.Recordset")
sRec.open "Select * from where .... conditions", oConn, adLockOptimistic, adOpenDynamic
for i = 0 to rs.EOF
ar[i] = sRec.fields(i)
next
NOTE : Incase rs.EOF does not work, try the following code -
dim item
For each item in sRec.fields
Next
sRec.MoveNext
Cheers......
Thanks, this was a really useful post
Hi ramya, here you can use this code for getting data from database by using msaccess..
''''''''''''''To Retrieve the Data From Database''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''To retrieve the data from two tables''''''''''''''''''''''''''''
Dim Dsn_conn,rs
Set objConnection=Createobject("ADODB.Connection")'Create connection object with DSN
Dsn_conn= "DSN=QT_Flight32;DBQ=C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight32.mdb;Driver=C:\WINNT\system32\odbcjt32.dll;DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"
objConnection.Open(Dsn_conn)'Open the connection
Set rs=CreateObject("ADODB.RecordSet") 'Create recordset object
Set rs=objconnection.execute("select Orders.Customer_Name,Flights.Departure from Orders,Flights where Orders.Flight_Number=Flights.Flight_Number")
rs.MoveFirst
row=1
datatable.GetSheet(1).addparameter"Customer_Name",""
datatable.GetSheet(1).addparameter"Departure",""
While Not rs.EOF
ONumber=rs.fields.item("Customer_Name")
CName=rs.fields.item("Departure")
datatable.SetCurrentRow(row)
datatable.Value (1,1)=ONumber
datatable.Value(2,1)=CName
row=row+1
rs.movenext
Wend
objConnection.Close
_________________________
[B][COLOR=Magenta]Thanks & Regards
Arun Singh Rajaputra[/COLOR][/B]
Hi Ramya,
Here you can use this code for getting data from database by using msaccess..
''''''''''''''To Retrieve the Data From Database''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''To retrieve the data from two tables''''''''''''''''''''''''''''
Dim Dsn_conn,rs
Set objConnection=Createobject("ADODB.Connection")'Create connection object with DSN
Dsn_conn= "DSN=QT_Flight32;DBQ=C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight32.mdb;Driver=C:\WINNT\system32\odbcjt32.dll;DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"
objConnection.Open(Dsn_conn)'Open the connection
Set rs=CreateObject("ADODB.RecordSet") 'Create recordset object
Set rs=objconnection.execute("select Orders.Customer_Name,Flights.Departure from Orders,Flights where Orders.Flight_Number=Flights.Flight_Number")
rs.MoveFirst
row=1
datatable.GetSheet(1).addparameter"Customer_Name",""
datatable.GetSheet(1).addparameter"Departure",""
While Not rs.EOF
ONumber=rs.fields.item("Customer_Name")
CName=rs.fields.item("Departure")
datatable.SetCurrentRow(row)
datatable.Value (1,1)=ONumber
datatable.Value(2,1)=CName
row=row+1
rs.movenext
Wend
objConnection.Close
_____________________
[COLOR="Magenta"]Thanks & Regards
Arunsingh Rajaputra
[/COLOR]