| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1226 人关注过本帖
标题:SqlDataReader dr=cm.ExecuteReader();
只看楼主 加入收藏
董晓云
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-4-5
结帖率:42.86%
收藏
已结贴  问题点数:10 回复次数:1 
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
 
搜索更多相关主题的帖子: class public 
2010-04-07 18:50
zhouz13
Rank: 2
等 级:论坛游民
帖 子:4
专家分:20
注 册:2010-4-6
收藏
得分:10 
select 语句错误  用and
2010-04-08 07:03
快速回复:SqlDataReader dr=cm.ExecuteReader();
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.073292 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved