vs.net vbscript连接数据库的问题
[code=C#][/code]
<script language="vbscript">
dim strconnection
dim conn
strconnection="dsn=wangzhan;driver={ mysql odbc 3.51 driver};server=localhost;uie=root;psw=test;database=wangzhan"
set conn = server.createobject("adodb.connection")
conn.open strconnection
</script>
<script language="vbscript">
set rs=server.CreateObject("ADODB.RecordSet");
//conn.CursorLocation=3;
conn.open connstr,User,Pass
sql = "select * from h_ziyuan "
//Set rs = conn.Execute(sql)
rs.open sql,conn,1,1
</script>
<%=rs("z_id")%>
编译器错误信息: CS0103: 当前上下文中不存在名称“rs”
显示上面错误,怎么连接数据库啊:
[解决办法]
加上runat="server"
<script language="vbscript" runat="server">
或者
全部写在<%%>中
<%dim strconnection dim conn strconnection="dsn=wangzhan;driver={ mysql odbc 3.51 driver};server=localhost;uie=root;psw=test;database=wangzhan" set conn = server.createobject("adodb.connection") conn.open strconnection set rs=server.CreateObject("ADODB.RecordSet"); //conn.CursorLocation=3; conn.open connstr,User,Pass sql = "select * from h_ziyuan " //Set rs = conn.Execute(sql) rs.open sql,conn,1,1 %><%=rs("z_id")%>