日期:2014-05-17  浏览次数:20953 次

运算符“&”无法应用于“bool”和“string”类型的操作数
登陆界面的用户名密码验证

CS0019: 运算符“&”无法应用于“bool”和“string”类型的操作数
用and好像也不行?


if (ds.Tables["t1"].Rows.Count ==1 & Login1.UserName = ds.Tables["t1"].Rows[0]["t1_username"].ToString() and Login1.Password = ds.Tables["t1"].Rows[0]["t1_pwd"].ToString() )  

  {
  Response.Write("登陆成功!");  

  }
  else
  {
  this.ClientScript.RegisterStartupScript(this.GetType(), "alter", "<script>alert(\"请检查用户名或密码\");</script> ");

------解决方案--------------------
if (ds.Tables["t1"].Rows.Count>0)//先判断数据有没有在判断密码用户名是否匹配比较好
{
if( Login1.UserName = ds.Tables["t1"].Rows[0]["t1_username"].ToString() && Login1.Password = ds.Tables["t1"].Rows[0]["t1_pwd"].ToString())
{
}
}


------解决方案--------------------
开始只看了第一个,后面也要改:
if (ds.Tables["t1"].Rows.Count ==1 && Login1.UserName == ds.Tables["t1"].Rows[0]["t1_username"].ToString() && Login1.Password == ds.Tables["t1"].Rows[0]["t1_pwd"].ToString() )
------解决方案--------------------
C# code
if (ds.Tables["t1"].Rows.Count ==1 && Login1.UserName == ds.Tables["t1"].Rows[0]["t1_username"].ToString() && Login1.Password == ds.Tables["t1"].Rows[0]["t1_pwd"].ToString() )

------解决方案--------------------
if (ds.Tables["t1"].Rows.Count ==1 && Login1.UserName == ds.Tables["t1"].Rows[0]["t1_username"].ToString() && Login1.Password == ds.Tables["t1"].Rows[0]["t1_pwd"].ToString() )