我数据库里有2个字段      name    和  pwd
   具体代码如下:    string  yonghuming=this.textbox1.text ;
     string       mima=this.textbox2.text ;     sqlconnection  con=new  sqlconnection("server=localhost;database=login;uid=sa;pwd=1234");
    
       string  sql="select  *  from  表名 where   name='"+yonghuming+"' and pwd='"+mima+"'";          sqlcommand  com=new  sqlcommand(sql,con);           con.open();             if (com.ExecuteNonQuery()>0) 
             {
                this.Label3.Text = "欢迎" + this.TextBox1.Text + "进入!";            }
            else
            {
                Response.Write("<script>alert('用户名或密码错误,请重新输入')</script>");
            }       
               con.close();
         执行后 总是 提示  “用户名或密码错误,请重新输入”               这段代码  哪错了

解决方案 »

  1.   

    Select 语句返回的结果总是 -1
      

  2.   

    可以用 SqlCeCommand.ExecuteScalar 来判断
      

  3.   

     
    #region   返回int类型
        public static int IsRead(SqlConnection sqlCon, string strCmd)
        {
            SqlCommand Cmd = new SqlCommand(strCmd, sqlCon);
            int num = Convert.ToInt32(Cmd.ExecuteScalar());
            return num;
        }
        #endregion
      

  4.   

    string yonghuming=this.textbox1.text ;
       string mima=this.textbox2.text ;   sqlconnection con=new sqlconnection("server=localhost;database=login;uid=sa;pwd=1234");
         
       string sql="select Count(*) from 表名 where name='"+yonghuming+"' and pwd='"+mima+"'";   sqlcommand com=new sqlcommand(sql,con);   con.open();   if (com.ExecuteScalar()>0)  
       {
       this.Label3.Text = "欢迎" + this.TextBox1.Text + "进入!";   }
       else
       {
       Response.Write("<script>alert('用户名或密码错误,请重新输入')</script>");
       }   
       con.close();
      

  5.   

    con.open();
    com.ExecuteNonQuery();
      if (com.ExecuteScalar()>0)  
      {
    }
      

  6.   

    如果用  
    com.ExecuteScalar()>0会提示出错  ———————— 运算符“>”无法应用于“object”和“int”类型的操作数
      

  7.   

     string yonghuming=this.textbox1.text ;
       string mima=this.textbox2.text ;   sqlconnection con=new sqlconnection("server=localhost;database=login;uid=sa;pwd=1234");
         
       string sql="select Count(*) from 表名 where name='"+yonghuming+"' and pwd='"+mima+"'";   sqlcommand com=new sqlcommand(sql,con);   con.open();   if (Convert.ToInt32(com.ExecuteScalar())>0)  
       {
       this.Label3.Text = "欢迎" + this.TextBox1.Text + "进入!";   }
       else
       {
       Response.Write("<script>alert('用户名或密码错误,请重新输入')</script>");
       }   
       con.close();
      

  8.   

    Convert.ToInt32(com.ExecuteScalar())>0ExecuteNonQuery对于select的返回值都是-1
    对于insert update delete的返回值是影响行数
      

  9.   


    好了   谢谢这位大哥  !!   ExecuteNonQuery对于select的返回值都是-1
    对于insert update delete的返回值是影响行数记住了!!结贴给分!!