Wednesday, February 16, 2011

Concept of ADODB Connection

Connection Object : The ADO Connection Object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database.

set objConnection=Server.CreateObject("ADODB.connection")

Recordset Object: The ADO Recordset object is used to hold a set of records from a database table. A Recordset object consist of records and columns (fields).

set objRecordset=Server.CreateObject("ADODB.recordset")

 Dim rs
 Dim sConStr
 Dim sQuery
 Dim sReturnVal
 Set objCon =Nothing
 sQuery = query  
 Set objCon =CreateObject("ADODB.Connection")
 If objCon.State <> 1 Then 
  db_server = "DSN:UserID:Passwd"
  dbstring = split(db_server,":")
  objCon.Open dbstring(0),dbstring(1),dbstring(2)  
  If objCon.State <> 1 then
   ReportResult("Fail","Connection state : " & objCon.State,"Unable to establish DB connection")
   ReportResult("Pass","Connection state : " & objCon.State,"Unable to establish DB connection")
  End if
 End If

Set rs = CreateObject("ADODB.Recordset")
 rs.Open sQuery,objCon,3,1
 If rs.State = 1 Then
  If rs.RecordCount > 0  Then
   sReturnVal = rs.Fields(0).Value
  End If
  sReturnVal = ""
 End If
 Set rs=Nothing
 Set objCon =Nothing

No comments:

Post a Comment