I am using below code:-

Function FetchValue_DataSource_AllValue_DataTable(strDataSource,strSqlQuery)

On Error resume Next

Dim oCon, oRes

err.clear

Set oCon = CreateObject(''ADODB.Connection'')

Set oRes = CreateObject(''ADODB.Recordset'')

oCon.Open strDataSource

If oCon.State = 1 Then

Set oRes = oCon.Execute(strSqlQuery)

oRes.Open strSqlQuery, oCon,3,3,1

If oRes.EOF = ''False'' Then

oRes.MoveFirst

intmaxCount = oRes.RecordCount

intColCount = oRes.Fields.Count

For j = 0 To intColCount -1 Step 1

datatable.LocalSheet.AddParameter oRes.Fields(j).Name,''''

Next

For i = 0 to intmaxCount-1

datatable.LocalSheet.SetCurrentRow(i+1)

For j = 0 To intColCount -1 Step 1

strDTColName = oRes.Fields(j).Name

strDBColName = oRes.Fields(j).Name

' If Instr(1,strDTColName, Then strDTColName = ''COUNT''

If strDTColName = ''COUNT(*)'' Then strDTColName = ''COUNT''

If IsNumeric(Mid(strDTColName,1,1)) Then strDTColName = ''_'' & strDTColName

datatable.Value(strDTColName,dtLocalSheet) = oRes.Fields(strDBColName).Value

Next

oRes.MoveNext

Next

Else

result= ''Null''

end If

Else

Call Sub_WriteToResultsLog(1,''Not able to connect with DB, Please Verify Manually'','''')

result= ''Null''

End If

If err.number <> 0 Then result= ''Null''

FetchValue_DataSource_AllValue_DataTable = result

If oRes.State = 1 Then oRes.Close

If oCon.State = 1 Then oCon.Close

Set oRes = Nothing

Set oCon = Nothing

On Error Goto 0

End Function