请问这是什么错误,应如何解决?

loepin 2003-12-07 08:09:47
代码:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="gb2312"%>
<%@ import namespace="system"%>
<%@ import namespace="system.data"%>
<%@ import namespace="system.data.sqlclient"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" Debug="true">
<title>test</title>
<script language="VB" runat="server">

sub check(sender as object,e as eventargs)
if request.form("txtname")="" or request.form("txtpsd")="" then
lbl.text="姓名和密码都不能为空!"
else
dim myconnection as sqlconnection
dim mycommand as sqlcommand
dim mydatareader as sqldatareader
dim tname as string=request.form("txtname")
dim tpsd as string=request.form("txtpsd")
dim mcmd as string="select id from message" _
&"where id='"& tname &"'" _
&" and where password='"& tpsd &"'"
myconnection=new sqlconnection("server=localhost;uid=sa;pwd=;database=lp")
mycommand=new sqlcommand(mcmd,myconnection)
mycommand.connection.open()
mydatareader=mycommand.executereader()
if mydatareader.read() then
response.Redirect("http://localhost/myweb/main.aspx")
else
lbl.text="对不起,请确认您输入的姓名和密码是否正确!"
end if
end if
end sub
</script>
</head>
<body onLoad="form.txtname.focus()">
<form id="form" action="" method="post" name="form" runat="server">
姓名:<asp:textbox Columns="20" ID="txtname" MaxLength="20" Rows="1" runat="server" TextMode="SingleLine" /><br>
密码:<asp:textbox Columns="20" ID="txtpsd" MaxLength="20" Rows="1" runat="server" TextMode="Password" /><br>
<asp:button ID="btn" runat="server" Text="登陆" OnClick="check"/><br>
<asp:label ID="lbl" runat="server"></asp:label>
</form>
</body>
</html>


错误提示:
Server Error in '/' Application.
--------------------------------------------------------------------------------

第 1 行: '=' 附近有语法错误。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:


[SqlException: 第 1 行: '=' 附近有语法错误。]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteReader() +42
ASP.TMP1qc3rpiwz2_aspx.check(Object sender, EventArgs e) +409
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
...全文
52 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
loepin 2003-12-08
  • 打赏
  • 举报
回复
我用英文的姓名的话可以,不过中文就不行了。
这是什么问题?
loepin 2003-12-08
  • 打赏
  • 举报
回复
我这里出错!!
你数据库中姓名和密码是英文还是中文的?
xueyhfeng 2003-12-08
  • 打赏
  • 举报
回复
上面的代码我刚才试过了,可以登陆,登陆成功后转到main.aspx ,
loepin 2003-12-08
  • 打赏
  • 举报
回复
我把代码改成如下形式可以运行,可是却没达到预期的结果。输入正确的姓名和密码却没反应
以下是代码请指教:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="gb2312"%>
<%@ import namespace="system"%>
<%@ import namespace="system.data"%>
<%@ import namespace="system.data.sqlclient"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="gb2312" Debug="true">
<title>test</title>
<script language="VB" runat="server">

sub check(sender as object,e as eventargs)
if trim(txtname.text)="" or trim(txtpsd.text)="" then
response.Redirect("test.aspx")
else
dim myconnection as sqlconnection
dim mycommand as sqlcommand
dim mydatareader as sqldatareader
dim tname as string=trim(txtname.text)
dim tpsd as string=trim(txtpsd.text)
dim mcmd as string="select id from message where id='"& tname &"' and password='"& tpsd &"'"


myconnection=new sqlconnection("server=localhost;uid=sa;pwd=;database=lp")
mycommand=new sqlcommand(mcmd,myconnection)
mycommand.connection.open()
mydatareader=mycommand.executereader()
if(mydatareader.read()) then
response.Redirect("main.aspx")
else
lbl.text="对不起,请确认您输入的姓名和密码是否正确!"
end if
mydatareader.close()
myconnection.close()
end if
end sub
</script>
</head>
<body onLoad="form.txtname.focus()">
<form id="form" action="" method="post" name="form" runat="server">
姓名:<asp:textbox Columns="20" ID="txtname" MaxLength="20" Rows="1" runat="server" TextMode="SingleLine" /><br>
密码:<asp:textbox Columns="20" ID="txtpsd" MaxLength="20" Rows="1" runat="server" TextMode="Password" /><br>
<asp:button ID="btn" runat="server" Text="登陆" OnClick="check"/><br>
<asp:label ID="lbl" runat="server"></asp:label>
</form>
</body>
</html>
loepin 2003-12-08
  • 打赏
  • 举报
回复
怎么没人来看啊。
loepin 2003-12-07
  • 打赏
  • 举报
回复
恩。不过我看不懂'" & tname &"'是什么意思。
还有,修改之后还是没有达到预期的目的。比如输入正确的姓名和密码后
lbl.text却显示
姓名和密码都不能为空!
这是什么原因呢?
warfen 2003-12-07
  • 打赏
  • 举报
回复
dim mcmd as string="select id from message" _
&"where id='"& tname &"'" _
&" and where password='"& tpsd &"'"
多写了一个 WHERE!!!
dim mcmd as string="select id from message where id='" & tname &"' and password='" & tpsd &"'" 这样写不是简单些???
loepin 2003-12-07
  • 打赏
  • 举报
回复
改了还是出现同样的错误提示。
qizhaopeng 2003-12-07
  • 打赏
  • 举报
回复
dim mcmd as string="select id from message" _
&"where id='"& tname &"'" _
&" and where password='"& tpsd &"'"
---------------------------------
查询语名多了个where ,去掉后面的一个where
---------------------------------
dim mcmd as string="select id from message" _
&"where id='"& tname &"'" _
&" and password='"& tpsd &"'"
loepin 2003-12-07
  • 打赏
  • 举报
回复
???
孟子E章 2003-12-07
  • 打赏
  • 举报
回复
<%@ Page Language="VB"%>

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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