gerritvankuipers / aspjson

Classic ASP JSON Class Reading/Writing
78 stars 40 forks source link

Variable uses an Automation type not supported in VBScript: 'TypeName' #2

Closed MatthK closed 3 years ago

MatthK commented 3 years ago

Just came across your Git and tried to create a short JSON file with it from a database query.

But when I try to run it I get the following error:

<p>Microsoft VBScript runtime </font> <font face="Arial" size=2>error '800a01ca'</font>
<p>
<font face="Arial" size=2>Variable uses an Automation type not supported in VBScript: 'TypeName'</font>
<p>
<font face="Arial" size=2>/includes/aspJSON1.18.asp</font><font face="Arial" size=2>, line 175</font> 

The script that I'm using is the following:

response.ContentType = "application/json"
Dim GetArray, vJSON
Set ConnObj=Server.CreateObject("ADODB.Connection")
ConnObj.Open myDSN
set rs = ConnObj.execute(strSQLA) 
If rs.BOF or rs.EOF Then
Else
   GetArray = rs.GetRows()
End If
rs.Close
ConnObj.Close
Set rs = Nothing
Set ConnObj = Nothing

'Write JSON

Set vJSON = New aspJSON

With vJSON.data
    For i = 0 to UBound(GetArray,2)
        .Add i, vJSON.Collection()
        With .item(i)
            .Add "Date", GetArray(0,i)
            .Add "Temperature", GetArray(1,i)
            .Add "Humidity", GetArray(2,i)
        End With
    Next
End With

Response.Write vJSON.JSONoutput()

And there is no "strange" data in the Query. This is the result I get from the database:

Date    Temperature Humidity
2020-12-31 12:25:00.000 -22.380000  0.000000
2020-12-31 12:30:00.000 -25.880000  0.000000
2020-12-31 12:35:00.000 -24.740000  0.000000
2020-12-31 12:40:00.000 -12.160000  0.000000
2020-12-31 12:45:00.000 20.640000   0.000000
2020-12-31 12:50:00.000 26.660000   0.000000
gerritvankuipers commented 3 years ago

Hi, sometimes SQL server database types don't match VB types. As a workaround you could change these lines: .Add "Temperature", cdbl(GetArray(1,i)) .Add "Humidity", cdbl(GetArray(2,i))