在SQL Server 2000中,有一个包含两个字段(每月苹果数量和每月橘子数量,针对两个季节)的简单表(Table1)。我需要使用Classic ASP提取这些字段的值,并填充两个数组。约束条件:这些数组已经由一款外部应用程序定义好了,因为我是Classic ASP的初学者,可能会出错,所以不需要太多修改。
这些数组的定义如下:
我已成功连接到数据库,提取数据并在浏览器中显示(格式为图形)。但是当我需要将其转移至数组(以便被那个现成的应用程序接管并处理它(以图形格式显示)时,我遇到了错误。以下是我的代码:
错误是:
任何提示都将不胜感激。
这些数组的定义如下:
Dim m_arrApples, m_arrOranges
我已成功连接到数据库,提取数据并在浏览器中显示(格式为图形)。但是当我需要将其转移至数组(以便被那个现成的应用程序接管并处理它(以图形格式显示)时,我遇到了错误。以下是我的代码:
'Open connection with SQL Server
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;server=" & NameServer & ";database=" & DataBaseName & ";uid=" & NameUser & ";pwd=" & DataBasePassword & ";"
'Open table and all records for further processing
dim strSQL
strSQL = "select * from " & Table1
Set rst = conn.Execute(strSQL)
'Going through the records in the table and try to get values of each field and allocate them to the array
If rst.BOF And rst.EOF Then
Response.Write "No data"
Else
i=0
Do While (Not rst.EOF)
i=i+1
'The line below confirms that the data extracted from database is displayed in the browser
'in its primary form (not graph), but that means I did it correctly up to this point
Response.Write rst("Apples") & "/" & rst("Oranges") & "<br>"
m_arrApples(i)= rst("Apples") ' THE ERROR IS AT THIS LINE. HERE THE SCRIPT IS STOPPED
m_arrOranges(i)= rst("Oranges")
rst.MoveNext
Loop
End If
错误是:
Microsoft VBScript runtime error '800a000d'
Type mismatch
任何提示都将不胜感激。
ReDim Preserve
。如果您已经知道数组的大小,请使用定长数组。(例如,如果您知道将有10个值,请使用Dim m_arrApples(9)
)。 - user692942Redim
实际上会将非数组变量转换为数组,但如果你将数组声明为数组,如Dim m_arrApples(),m_arrOranges()
,那么你的代码将更容易理解。 - MarthaReDim
就无关紧要了。然而,仍有一个强有力的理由使用Dim yourvar()
,那就是IsArray()
始终为True
,而Dim yourvar
只是一个变量,因此它将返回False
-请参见Dim output() versus Dim output。 - user692942