Thursday, March 31, 2011

Retrive the column data from database in vbscript


Function retrive_Column_Data()
    Dim fieldname1 As String
    Dim cntAs Integer
    Dim fieldsArr()
   
    cnt= 0
    Set rs = CreateObject("adodb.recordset")
  
    sqlquery = "enter here Select query"
    Set rs = CreateObject("adodb.recordset")
    rs.Open sqlquery, con
    rs.movefirst
   
    While Not rs.EOF
       
        cnt= cnt+ 1       
        rs.movenext
       
    Wend
   
    rs.movefirst
    ReDim testdatadetailsarr(cnt- 1)
   
    While Not rs.EOF
       
        For I = 0 To cnt- 1
            fieldname1 = rs("dbcolumnName_1")
            fieldname2=  rs("dbcolumnName_2")
            fieldsArr(I) = fieldname1 & "," & fieldname2
            rs.movenext
           
        Next
       
    Wend
   
    retrive_Column_Data= fieldsArr
    Set rs = Nothing
    Erase fieldsArr

End Function

No comments: