string selectStr = " select * from Administrator where name="'"+this.textBox1 .Text+"'"+and password="'"+this.textBox2.Text+"'"";
textBox1 要求用户输入 用户名
textBox2 要求用户输入 密码先谢 高手们啦!

解决方案 »

  1.   

    string   selectStr   =   "   select   *   from   Administrator   where   name='"+this.textBox1.Text+"' and   password='"+this.textBox2.Text+"'"";
    這樣試試
      

  2.   

    string selectStr= "select * from Administrator where name='"+this.textBox1.Text+"'and password='"+this.textBox2.Text+"'";用斷點查看下selectStr的值。
      

  3.   

    这句话应该没错可能是这样,你在数据库中的密码是char(10)但密码只有五位,那那五位就是空格所以在比较的时候是不正确的你看看数据类型有没有什么问题的,改成varchar的试试
      

  4.   

    string   selectStr   =   string.fromat("select   *   from   Administrator   where   name={0} and password={1}",this.textBox1.Text,this.textBox2.Text);
    这样语法没错,不过你这样会被sql注入的,要用参数。
      

  5.   

    string selectStr="select * from Administrator where name='"+this.textBox1.Text+"'and password='"+this.textBox2.Text+"'";
      

  6.   

    to bb_chen
    真谢谢你啊。 那个断点查看还不会,我得看下《C#入门经典》。to zhengbr
    密码 我设的是 varchar(20)
      

  7.   

    string selectStr=string.Format("select * from Administrator where name='{0}' and password='{1}'",this.textBox1.Text,this.textBox2.Text);
      

  8.   

    再次谢谢 bb_chen
    运行成功了。
    也谢谢大家对我的热心帮助!