各位请帮忙…用array 做sql 的句子…

artai 2002-01-02 12:19:41
The array ‘strCls_id’ now is assigned (30) size but I want to use the ‘i’ that count by the recordset ‘rstClsPart’ to assigned to the array‘strCls_id’ but vbscript not allowed since it is variable not constant .
How can I do?


<%
Set cnnDB = Server.CreateObject("ADODB.Connection")

StrCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./MainV1.1.mdb")

cnnDB.Open StrCon '-----Open the database-----

Set rstClsPart = Server.CreateObject ("ADODB.Recordset")
'-----get the Class Part table-----

'-----get the cls_id (class that the lecturer teach)------
SQL_ClsPart_clsid = "SELECT cls_id FROM [Class Part] WHERE lect_id='00013' ORDER BY cls_id ASC"

rstClsPart.Open SQL_ClsPart_clsid,cnnDB

dim i
i=0
%>
 <p> </p>
<p>
<SELECT size=12 ID=SelectCls>


<%
'-------Count the number of the required class--------
Do While Not rstClsPart.EOF
i=i+1
rstClsPart.MoveNext
Loop
'-------Write the list about the class that the lecturer teach-------
rstClsPart.MoveFirst
i=i-1 '----start from zero condition-----

dim strCls_id(30)

For num = 0 to i
%>
<OPTION value=<%=rstClsPart("cls_id")%>>
<% strCls_id(i)=rstClsPart("cls_id")
Set rstCls = Server.CreateObject ("ADODB.Recordset")

'-------Using the cls_id to get the cos_id and cls_desp in class table------
SQL_Cls_all = "SELECT * FROM Class WHERE cls_id ='"&strCls_id(i)&"'"
rstCls.Open SQL_Cls_all,cnnDB
'-------Write class in the list-----
Response.Write(rstCls("cos_id")&"/"&rstCls("cls_desp"))

rstCls.Close
Set rstCls = Nothing
%>
</OPTION>
<%
rstClsPart.MoveNext
Next

rstClsPart.Close
Set rstClsPart = Nothing
cnnDB.Close
Set cnnDB = Nothing
%>
</SELECT></p>
...全文
114 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
artai 2002-01-02
  • 打赏
  • 举报
回复
该怎办呢?
mm1258 2002-01-02
  • 打赏
  • 举报
回复
关于数组:
可用redim重定义其大小。

dim str()
'......
redim str(10)
'.......
redim str(100)
,.......
size=1000
redim str(size)
mm1258 2002-01-02
  • 打赏
  • 举报
回复
<%
Set cnnDB = Server.CreateObject("ADODB.Connection")
StrCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./MainV1.1.mdb")

cnnDB.Open StrCon

Set rstClsPart = Server.CreateObject ("ADODB.Recordset")
SQL_ClsPart_clsid = "SELECT cls_id FROM [Class Part] WHERE lect_id='00013' ORDER BY cls_id ASC"

rstClsPart.Open SQL_ClsPart_clsid,cnnDB

Set rstCls = Server.CreateObject ("ADODB.Recordset")

%>
<SELECT size=12 ID=SelectCls>
<%
Do While Not rstClsPart.EOF
%>
<OPTION value=<%=rstClsPart("cls_id")%>>
<%
SQL_Cls_all = "SELECT * FROM Class WHERE cls_id ='"&rstClsPart("cls_id")&"'"
rstCls.Open SQL_Cls_all,cnnDB
Response.Write(rstCls("cos_id")&"/"&rstCls("cls_desp"))
rstCls.Close
%>
</OPTION>
<%
rstClsPart.MoveNext
Loop

rstClsPart.Close
Set rstClsPart = Nothing
Set rstCls = Nothing

cnnDB.Close
Set cnnDB = Nothing
%>
</SELECT></p>


更简单的方法:


<%
Set cnnDB = Server.CreateObject("ADODB.Connection")
StrCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./MainV1.1.mdb")

cnnDB.Open StrCon


sqlcommand="select cls_id,cos_id,cls_desp from class where cls_id in (select cls_id from [class part] where lect_id='00013' order by cls_id asc)"

set rs=cnndb.execute(sqlcommand,30,1)

%>
<SELECT size=12 ID=SelectCls>
<%
Do While Not rs.EOF
%>
<OPTION value=<%=rs("cls_id")%>>
<%=rs("cos_id")&"/"&rs("cls_desp")%>
</OPTION>
<%
rs.MoveNext
Loop

rs.Close
Set cnnDB = Nothing
%>
</SELECT></p>
artai 2002-01-02
  • 打赏
  • 举报
回复
O~~
明白~~
但那個array 的()裡的數字可以是未知數嗎?

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧