日期:2014-05-18  浏览次数:20850 次

大神给看看这段验证登录代码,怎么输都显示登录失败
SqlConnection conn = new SqlConnection("server =127.0.0.1;uid = sa; pwd =allen;database =MaterialDataBase");
  string cmd = "select * from Users where UserName='textBox1.Text' and Password='textBox2.Text'";
  SqlCommand command = new SqlCommand(cmd,conn);
  conn.Open();
  SqlDataReader read = command.ExecuteReader();
  if (read.Read())
  { 
  MessageBox.Show("登陆");
  this.DialogResult = DialogResult.OK;
   
  }
  else
  {
  MessageBox.Show("登陆失败"); 
  this.DialogResult = DialogResult.Cancel; 
  }

------解决方案--------------------
C# code
string cmd = "select * from Users where UserName='textBox1.Text' and Password='textBox2.Text'";