JAVASCRIPT 转换成 VB script
下布这段JAVASCRIPT如何转换成VBScript?functionOpenDB(sdbname){/**---------------OpenDB(sdbname)...
下布这段JAVASCRIPT如何转换成 VB Script?
function OpenDB(sdbname)
{
/*
*--------------- OpenDB(sdbname) -----------------
* OpenDB(sdbname)
* 功能:打开数据库sdbname,返回conn对象.
* 参数:sdbname,字符串,数据库名称.
* 实例:var conn = OpenDB("database.mdb");
*--------------- OpenDB(sdbname) -----------------
*/
var connstr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(sdbname);
var conn = Server.CreateObject("ADODB.Connection");
conn.Open(connstr);
return conn;
}
var oConn = OpenDB("../../Data_command/Cyd#lxgcsj.mdb");
var sel = Request("sel");
var TableName = Request("TableName") //获得表名
var Menu =Request("MenuId")
if (TableName == "" ){
TableName=="NewsClass2"
}
var classid = Request("classid") //获得ID
var fieldname = Request("fieldname")//获得字段名
var arrResult = new Array();
//var sql = "select "+fieldname+" from Demo where parentid='"+sel+"' and classid="+classid;
var sql = "select "+Menu+","+fieldname+" from "+TableName+" where BID='"+sel+"'";
//Response.Write("alert("+sql+")")
var rs = Server.CreateObject("ADODB.Recordset");
rs.Open(sql,oConn,1,1);
while(!rs.EOF)
{
//遍历所有适合的数据放入arrResult数组中.
arrResult[arrResult.length] = rs(0).Value+"|"+rs(1).Value;
rs.MoveNext();
}
//escape解决了XMLHTTP。中文处理的问题.
//数组组合成字符串.由","字符串连接.
Response.Write(escape(arrResult.join(",")));
我自己转的
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include File="CommandConn.asp"-->
<%Dim sel,TableName,Menu,classid,fieldname,arrResult,sql_s,rs_s
sel = Request("sel")
TableName = Request("TableName")
Menu = Request("MenuId")
If TableName ="" then
TableName="NewsClass2"
End if
classid = Request("classid") '//获得ID
fieldname = Request("fieldname")'//获得字段名
arrResult = Array()
'sql_s = "select "&Menu&","&fieldname&" from "&TableName&" where BID="&sel
sql_s = "select ID,first from "&TableName&" where BID='' "
Set rs_s = Server.CreateObject("ADODB.Recordset")
rs_s.Open sql_s,Conn,1,1
do while not rs_s.Eof
'遍历所有适合的数据放入arrResult数组中.
arrResult[arrResult.length] = rs_s(0).Value&"|"&rs_s(1).Value
rs.MoveNext
loop
'escape解决了XMLHTTP。中文处理的问题.
'数组组合成字符串.由","字符串连接.
Response.Write(escape(arrResult.join(",")))
%>
但是上面这种方法在数组这里报错。请高手帮忙,感激不尽! 展开
function OpenDB(sdbname)
{
/*
*--------------- OpenDB(sdbname) -----------------
* OpenDB(sdbname)
* 功能:打开数据库sdbname,返回conn对象.
* 参数:sdbname,字符串,数据库名称.
* 实例:var conn = OpenDB("database.mdb");
*--------------- OpenDB(sdbname) -----------------
*/
var connstr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(sdbname);
var conn = Server.CreateObject("ADODB.Connection");
conn.Open(connstr);
return conn;
}
var oConn = OpenDB("../../Data_command/Cyd#lxgcsj.mdb");
var sel = Request("sel");
var TableName = Request("TableName") //获得表名
var Menu =Request("MenuId")
if (TableName == "" ){
TableName=="NewsClass2"
}
var classid = Request("classid") //获得ID
var fieldname = Request("fieldname")//获得字段名
var arrResult = new Array();
//var sql = "select "+fieldname+" from Demo where parentid='"+sel+"' and classid="+classid;
var sql = "select "+Menu+","+fieldname+" from "+TableName+" where BID='"+sel+"'";
//Response.Write("alert("+sql+")")
var rs = Server.CreateObject("ADODB.Recordset");
rs.Open(sql,oConn,1,1);
while(!rs.EOF)
{
//遍历所有适合的数据放入arrResult数组中.
arrResult[arrResult.length] = rs(0).Value+"|"+rs(1).Value;
rs.MoveNext();
}
//escape解决了XMLHTTP。中文处理的问题.
//数组组合成字符串.由","字符串连接.
Response.Write(escape(arrResult.join(",")));
我自己转的
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include File="CommandConn.asp"-->
<%Dim sel,TableName,Menu,classid,fieldname,arrResult,sql_s,rs_s
sel = Request("sel")
TableName = Request("TableName")
Menu = Request("MenuId")
If TableName ="" then
TableName="NewsClass2"
End if
classid = Request("classid") '//获得ID
fieldname = Request("fieldname")'//获得字段名
arrResult = Array()
'sql_s = "select "&Menu&","&fieldname&" from "&TableName&" where BID="&sel
sql_s = "select ID,first from "&TableName&" where BID='' "
Set rs_s = Server.CreateObject("ADODB.Recordset")
rs_s.Open sql_s,Conn,1,1
do while not rs_s.Eof
'遍历所有适合的数据放入arrResult数组中.
arrResult[arrResult.length] = rs_s(0).Value&"|"&rs_s(1).Value
rs.MoveNext
loop
'escape解决了XMLHTTP。中文处理的问题.
'数组组合成字符串.由","字符串连接.
Response.Write(escape(arrResult.join(",")))
%>
但是上面这种方法在数组这里报错。请高手帮忙,感激不尽! 展开
1个回答
展开全部
VBS 的数组没有 JS 的强大 不能那么用.
'===============================================
Function OpenDB(sdbname)
Set OpenDB = Server.CreateObject("ADODB.Connection")
OpenDB.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(sdbname)
End Function
Dim oConn, sel, TableName, Menu, classid, fieldname, sql, rs, strResult
Set oConn = OpenDB("../../Data_command/Cyd#lxgcsj.mdb")
sel = Request("sel")
TableName = Request("TableName") '获得表名
Menu = Request("MenuId")
If TableName = "" Then
TableName = "NewsClass2"
End If
classid = Request("classid") '获得ID
fieldname = Request("fieldname") '获得字段名
strResult = ""
' var sql = "select "+fieldname+" from Demo where parentid='"+sel+"' and classid="+classid;
sql = "select "+Menu+","+fieldname+" from "+TableName+" where BID='"+sel+"'"
' Response.Write("alert("+sql+")")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, oConn, 1, 1
While Not rs.EOF
strResult = strResult & rs(0).Value & "|" & rs(1).Value
rs.MoveNext
If Not rs.EOF Then strResult = strResult & ","
Wend
rs.Close
'escape解决了XMLHTTP。中文处理的问题.
'数组组合成字符串.由","字符串连接.
Response.Write Escape(strResult)
'===============================================
Function OpenDB(sdbname)
Set OpenDB = Server.CreateObject("ADODB.Connection")
OpenDB.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(sdbname)
End Function
Dim oConn, sel, TableName, Menu, classid, fieldname, sql, rs, strResult
Set oConn = OpenDB("../../Data_command/Cyd#lxgcsj.mdb")
sel = Request("sel")
TableName = Request("TableName") '获得表名
Menu = Request("MenuId")
If TableName = "" Then
TableName = "NewsClass2"
End If
classid = Request("classid") '获得ID
fieldname = Request("fieldname") '获得字段名
strResult = ""
' var sql = "select "+fieldname+" from Demo where parentid='"+sel+"' and classid="+classid;
sql = "select "+Menu+","+fieldname+" from "+TableName+" where BID='"+sel+"'"
' Response.Write("alert("+sql+")")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, oConn, 1, 1
While Not rs.EOF
strResult = strResult & rs(0).Value & "|" & rs(1).Value
rs.MoveNext
If Not rs.EOF Then strResult = strResult & ","
Wend
rs.Close
'escape解决了XMLHTTP。中文处理的问题.
'数组组合成字符串.由","字符串连接.
Response.Write Escape(strResult)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询