经典asp从记录集错误创建数组

时间:2013-10-28 20:20:44

标签: sql-server arrays asp-classic

我收到错误:

Category:Microsoft VBScript runtime 
Description:Subscript out of range
Line:46

来自以下代码:

<%
''*************************************************************************
''Created Date: 10/28/13
''Created By:   NG
''Description:  Test page for new highcharts charts replacing ChartFX for business trends
''History:      N/A
''*************************************************************************

'OPEN CONNECTION TO SQL SERVER
'-create objects
Set adoCon = Server.CreateObject("ADODB.Connection")
Set adoRsGraph = Server.CreateObject("ADODB.Recordset")
Set adoCom = Server.CreateObject("ADODB.Command")
'-open connection

'scon = "FILE NAME=" & server.MapPath("/d_support") & "\cfn_datastore_heracles.udl"
scon = "FILE NAME=" & server.MapPath("/d_support") & "\cfn_datastore.udl"

adoCon.Open sCon

adoCom.CommandType= 4
adoCom.ActiveConnection = sCon
'GET RECORDSET DATA NEEDED TO FILL IN THE ACCOUNT BALANCE CHART
'-call stored proc to retrieve data

    adoCom.CommandText="sp_Chart_AccountBalance3"
    adoCom.Parameters(1) = 21820

adoRsGraph.CursorLocation = 3
adoRsGraph.Open adoCom

dim xAxisData()
dim yAxisData()
j = 0               
    adoRsGraph.MoveFirst            
if adoRsGraph.EOF = false then

    Do Until adoRsGraph.EOF
        xAxisData(j) = adoRsGraph("Value")
        yAxisData(j) = adoRsGraph("Date")

        j = j + 1
        adoRsGraph.MoveNext
    Loop
end if
%>

我不完全确定第46行是什么,但我认为它必须在我的循环中通过记录集。我在运行时已经完成了跟踪,并且看到正确调用了sproc,并且在SQL Server中运行时它包含数据集中的记录,那么为什么我的循环不能为数组赋值?

1 个答案:

答案 0 :(得分:1)

您已经创建了两个数组,但在给它们大小之前不能使用它们。

使用ReDim命令在将值放入其中之前调整数组的大小:

ReDim xAxisData(j)
ReDim yAxisData(j)