Thursday, 21 July 2011

How to connect Database and retrieve date’s from Database?

'Variable Declaration
 
Option Explicit
Dim Dsn_conn,rs,PTime,NowDate
Dim myarray,DiffADate
Dim strServer,strUid,strQry
Dim objConnection
 
' Action parameters
 
strServer=parameter("Server") ' This is Server Name
strUid=parameter("Uid") ' User Id
Set objConnection=Createobject("ADODB.Connection")
 
Dsn_conn="DRIVER=SQL Server;SERVER="&strServer&";UID="&strUid&";APP=QuickTest Professional;WSID="&strServer&";Trusted_Connection=Yes"
 
objConnection.Open(Dsn_conn)
 
If err.number <> 0 Then
Reporter.ReportEvent 1 ,"DBConnection","Unable to Connect to the database"&"Err Description = " & err.Description
Else
Reporter.ReportEvent 0 ,"DBConnection","Connection Succeeded"
End If
 
Set rs=CreateObject("ADODB.RecordSet")
strQry = "UPDATE ELinkQueues.dbo.ELKMasterArchive SET ProcessedTime = DATEADD(""Day"", -10, ProcessedTime) WHERE (ProcessedTime IS NOT NULL) AND (Status = 2 OR Status = 3)" ' this is Query
 
Set rs=objconnection.execute(strQry)
Set rs=objconnection.execute("Select * from d_name from Doctordt")
rs.MoveFirst
Do While Not rs.EOF
PTime=rs.fields.item("ProcessedTime")
Exit Do
rs.movenext
Loop
rs.Close
objConnection.Close

No comments:

Post a Comment