Search code examples
asp-classicvbscriptado

ADO Recordset Decimal value issue


I have code similar to

Dim A, B, C
Set rs = Server.CreateObject("ADODB.Recordset")
strSql = "Exec [dbo].[some_sp] IND"
rs.open strSql,CN,3,3

Do While Not rs.EOF

'these columns are returned as decimal(10,2) format
A = rs("col1")
B = rs("col2")

rs.MoveNext
Loop

C = A + B 'i get type mismatch error here

And I used response.write to check values for A, B they are in integer format and not decimal

Do i have to format recordset again to set decimal values? And what could be possible problem for type mismatch as all values are integer (even if they are decimal) ?


Solution

  • Variables in ASP/VBScript are just variant types so you may need to convert the values explicitly.

    C = CDbl(A) + CDbl(B)
    

    However, my guess would be that one of your rows does not have a numeric value for col1 or col2. Do you know what the values of those are when you get the type mismatch error?