Pages

QTP-Database Connection Using ADODB



1. ADODB. Connection  (connection in java script)
we can use this class to establish onneton to database
to us the methods of this class create an object like below
syn: set objname= createobject ("connection")
 eg : set reynolds = createobject("pen")
(object) (class)
Example :
Dim cn
set cn= createobject ("ADODB.connection")
Ms-Access : cn.open" provider= microsoft.jet.dedb.4.0: database=path
of db" Ms-Access
(cn.open"DSN=datasourcename")
Sql server: cn.open' provider = SQLOLEDB; datasource= serveaddress;
vid= "--";pwd="--"; database=dbname"
 SQL server
oracle : cn.open provider=MSDAORA; database=address=; vid="--";pwd="--";"      
'providers can be of different kinds , ask your
developer to know the exact provider which thery using
cn.open  : will establish connection to database
'**********************************************************************************************
2.  ADODb.command
we can use this class to perform  the DML transaction insert, update & delete
'syn: set command name = createobject("ADOBE.command")
Example :
dim cn,cmd
set cn= createobject("ADODB.connection"
set cmd= createobject("ADODB.command")
cn.open "DSN=r1"
cmd.activeconnection=cn
cmd.commandtext="insert into emp values('002', 'james', 20000)"
cmd. execute
'**********************************************************************************************
'3.  ADODB.recordset
we can use this class to select the data form existing data files. any data
selected from the db is stored in record set object
syn: set record set name = create object ("ADODB.recordset")

Example :
   dim cn,rs
   set cn= createobject ("ADODB.connection")
   set rs= createobject ("ADODB.recordset")
   cn.open "DSN=r1"
   rs.open "select*from emp",cn
   rs.move first
   while rs.eof<>true
   msgbox rs ("eno") & "  " & ("ename")& "  " &("sal")
   rs.movenext
   wend
   cn.close
**************************************************************************************************
record set object has the below methods
1) rs.open  : this method is used to execute the SQL statement and select records
 form database
syntax :  rs.open "sql statement", connection object
 rs.movefirst - goto first record
 rs.movenext  _ goto next record
rs.moveprev  _ goto previous record
 rs.movelast  _ goto last record
rs.rowcount  _ count no.of records
 rs ("fieldname") _ select the value in the field
 rs.close     _ close recordset object


0 comments:

Post a Comment