SqlDataReader dr=cm.ExecuteReader();
using System;using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void login_Click(object sender, EventArgs e)
{
string log_n = a_n.Text;
string log_d = a_d.Text;
SqlConnection cn = new SqlConnection("server=127.0.0.1;uid=sa;pwd=1234;database=w");
cn.Open();
string sql="select * from admin where a_name='"+log_n+"',u_pwd='"+log_d+"'";
SqlCommand cm = new SqlCommand(sql,cn );
SqlDataReader dr=cm.ExecuteReader();
if (dr.Read())
{
Response.Redirect("adimn.aspx");
}
cn.Close();
}
}
}
单击login按钮 后出现以下错误
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
',' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: ',' 附近有语法错误。
源错误:
行 29: string sql="select * from admin where a_name='"+log_n+"',u_pwd='"+log_d+"'";
行 30: SqlCommand cm = new SqlCommand(sql,cn );
行 31: SqlDataReader dr=cm.ExecuteReader();
行 32: if (dr.Read())
行 33: {
源文件: C:\Documents and Settings\dongxiaoyun\My Documents\Visual Studio 2005\Projects\WebApplication1\WebApplication1\Default.aspx.cs 行: 31
堆栈跟踪:
[SqlException (0x80131904): ',' 附近有语法错误。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +946986
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +821638
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteReader() +84
WebApplication1._Default.login_Click(Object sender, EventArgs e) in C:\Documents and Settings\dongxiaoyun\My Documents\Visual Studio 2005\Projects\WebApplication1\WebApplication1\Default.aspx.cs:31
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint