日期:2014-05-17  浏览次数:20934 次

从asp.net开始学。现在要用到asp,烦人,请教。
<%@   LANGUAGE= "VBSCRIPT "   CODEPAGE= "950 "%>

<SCRIPT   LANGUAGE= "VBScript ">  

dim   connstr,conn,record,sql
connstr= "Driver={SQL   Server};Server=.;Uid=sa;pwd=sa;Database=Lpos5_B_dingguagua; "

Set   conn   =   Server.Createobject( "ADODB.Connection ")   '这有错
conn.CommandTimeout   =   2000
conn.open   connstr
Set   Record=Server.CreateObject( "Adodb.Recordset ")
sql   =   "execute   get_billnum "
Record.Open   sql,conn
msgbox   Record( "rt ")


</SCRIPT>  
<HTML>
<HEAD> <TITLE> </TITLE>
</HEAD>
<BODY>
<HR>
<FORM     id= "MyForm "   name= "MyForm "     method= "post "   action= "test.asp ">

</FORM>
</BODY>
</HTML>


为什么这样有错?把程序代码放入 <%   %> 里就没有问题,怎么解决?

------解决方案--------------------
那就把它放到 <%%> 里好了,如果想在客户端连接数据库那还是用AJAX-------------菜鸟的意见
------解决方案--------------------
asp一定要放在 <% %> 里面 不然系统就不认为这个是代码.
<%
dim connstr,conn,record,sql
connstr= "Driver={SQL Server};Server=.;Uid=sa;pwd=sa;Database=Lpos5_B_dingguagua; "

Set conn = Server.Createobject( "ADODB.Connection ") '这有错
conn.CommandTimeout = 2000
conn.open connstr
Set Record=Server.CreateObject( "Adodb.Recordset ")
sql = "execute get_billnum "
Record.Open sql,conn
msgbox Record( "rt ")
%>
要这样不然肯定不行
------解决方案--------------------
<%@ LANGUAGE= "VBSCRIPT " CODEPAGE= "950 "%>

<SCRIPT LANGUAGE= "VBScript " Runat= "Server ">
Sub cmdChangeIt_onClick
dim connstr,conn,record,sql
connstr= "Driver={SQL Server};Server=.;Uid=sa;pwd=sa;Database=Lpos5_B_dingguagua; "
Set conn = Server.Createobject( "ADODB.Connection ") '这有错
conn.CommandTimeout = 2000
conn.open connstr
Set Record=Server.CreateObject( "Adodb.Recordset ")
sql = "select getdate() as rt "
Record.Open sql,conn
msgbox Record( "rt ")
End Sub

If Request.ServerVariables( "REQUEST_METHOD ") = "POST " Then
If Request.Form( "cmdChangeIt ") = "ent " Then
Call cmdChangeIt_onClick
End If
End If
</SCRIPT>
<HTML>
<HEAD> <TITLE> </TITLE>
</HEAD>
<BODY>
<HR>
<FORM id= "MyForm " name= "MyForm " method= "post " action= "test.asp ">
<INPUT TYPE= "submit " NAME= "cmdChangeIt " VALUE= "ent " />
</FORM>
</BODY>
</HTML>

------解决方案--------------------
把你要运行的代码写在你提交的目的页的 <% %> 里
<INPUT TYPE= "BUTTON " NAME= "cmdChangeIt " VALUE= "ent ">
--》
<input type= "submit " value= "submit ">


server端的代码不能用msgbox()


------解决方案--------------------