大家帮我看看到底是哪里错了?数据库名字:购物系统    表:用户表    字段:序列编号、姓名、密码。protected void Login_Click(object sender, EventArgs e)
        {
            string username = tbUsername.Text;
            string password = tbPassword.Text;
           
           string ConnectionString = "Server=(local);User id=sa;Pwd=123;Database=购物系统";//连接数据库字符串 
            string Sql = "SELECT   *   FROM   用户表   WHERE   姓名='" + username+ "'";
            
            SqlConnection Connection = new SqlConnection(ConnectionString);   //创建SqlConnection对象 
            SqlCommand Command = new SqlCommand(Sql, Connection);            Command.CommandText = "SELECT   密码    FROM   用户表   where   姓名='" + username + "'";
 
             Command.CommandType = CommandType.Text;            try
            {
                Command.Connection.Open();//打开数据库连接                  
                object test = Command.ExecuteScalar();//获取查询结果  
                Response.Write (test);      
                SqlDataReader dr = Command.ExecuteReader();//执行SQL语句返回DataReader对象
                while (dr.Read())
                {
                    string strpassword = dr["密码"].ToString();//强制转换成STRING型数据   
                    Response.Write(strpassword);                    if (password == strpassword)
                    {
                        Response.Redirect("default.aspx");
                    }
                    else
                    {
                        string message = ("对不起,您输入的内容有误!");
                        Response.Redirect("index.aspx?MSG=" + message);
                    }                }
               
                dr.Close();  //关闭   DataReader               }
            catch (SqlException ex)
            {
                //Response.Write   ("数据库连接失败");   
                //Response.Write   (ex);   
            }
            finally
            {
                Connection.Close();//关闭数据库
                Command.Connection.Close();  //关闭数据库连接               }           }

解决方案 »

  1.   

    catch (SqlException ex)
    你把这里的SqlException换成Exception呢,看看会不会提示错误
      

  2.   

    数据库名字:购物系统 表:用户表 字段:序列编号、姓名、密码。protected void Login_Click(object sender, EventArgs e)
    {
         string username = tbUsername.Text;
         string password = tbPassword.Text;
         string ConnectionString = "Server=(local);User id=sa;Pwd=123;Database=购物系统";//连接数据库字符串 
          string Sql = "SELECT * FROM 用户表 WHERE 姓名='" + username+ "'";      SqlConnection Connection = new SqlConnection(ConnectionString); //创建SqlConnection对象 
           SqlCommand Command = new SqlCommand(Sql, Connection);      Command.CommandText = "SELECT 密码 FROM 用户表 where 姓名='" + username + "'";      Command.CommandType = CommandType.Text;     try
         {
          Command.Connection.Open();//打开数据库连接 
           object test = Command.ExecuteScalar();//获取查询结果 
           Response.Write (test); 
          SqlDataReader dr = Command.ExecuteReader();//执行SQL语句返回DataReader对象
           while (dr.Read())
           {
           string strpassword = dr["密码"].ToString();//强制转换成STRING型数据 
            Response.Write(strpassword);
            if (password == strpassword)
              {
                Response.Redirect("default.aspx");
              }
            else
              {
               string message = ("对不起,您输入的内容有误!");
               Response.Redirect("index.aspx?MSG=" + message);
              }      }        dr.Close(); //关闭 DataReader     }
          catch (SqlException ex)
             {
               //Response.Write ("数据库连接失败"); 
              //Response.Write (ex); 
             }
         finally
            {
              Connection.Close();//关闭数据库
               Command.Connection.Close(); //关闭数据库连接           } }
      

  3.   

    catch (SqlException ex)
    {
    //Response.Write ("数据库连接失败"); 
    //Response.Write (ex); 
    }改成catch (SqlException ex)
    {
          Response.Write ("数据库连接失败"); 
          Response.Write (ex); 
    }
      

  4.   

    catch里的信息都被你注释掉了,就表示出现异常什么事情都不做。所以没有任何的提示。也没有任何的反应了
      

  5.   

    Command.CommandText = "SELECT 密码 FROM 用户表 where 姓名='" + username + "'";
    好像用了同一个command对象来接收sql语句,好像无法识别
      

  6.   

    string Sql = "SELECT * FROM 用户表 WHERE 姓名='" + username+ "'";那是“'”还是“’”?