07-09-2008, 05:57 PM
Below is the code using which you can retieve data from the DB and stores in a Sample Array
Code:
Function GetDBQueryData_Fun (sClient, sQuery)
Dim sDataSource
sDataSource = envDBInstance
Dim strConnection, oDbConn, rs, strSQL
strConnection = "Provider=OraOLEDB.Oracle;Data Source="&sDataSource&";User Id="&sClient&";Password="&sClient&";"
Set oDbConn = CreateObject("ADODB.Connection")
oDbConn.Open strConnection
If oDbConn.State <> 1 Then
Reporter.ReportEvent micFail, "Unable to Connect", "Unable to Connect to the DB using the Schema " & sClient
ExitComponentIteration
End if
Set oResultSet = CreateObject("ADODB.recordset")
oResultSet.open sQuery, oDbConn, 3,3
If oResultSet.EOF Then
oResultSet.close
Set oResultSet = Nothing
oDbConn.Close
Set oDbConn = Nothing
GetDBQueryData_Fun = Array("")
Exit Function
End If
oResultSet.MoveFirst
Dim arrOutput()
Dim iIter, sDBRow,i
iIter = 0
Do Until oResultSet.EOF
sDBRow = ""
For i = 0 to oResultSet.Fields.Count - 1
If i = 0 Then
sDBRow = oResultSet.Fields(i)
Else
sDBRow = sDBRow&"<NextCol>" & oResultSet.Fields(i)
End If
Next
ReDim Preserve arrOutput(iIter)
arrOutput(iIter) = sDBRow
iIter = iIter + 1
oResultSet.MoveNext
Loop
oResultSet.close
Set oResultSet = Nothing
oDbConn.Close
Set oDbConn = Nothing
GetDBQueryData_Fun = arrOutput
End Function