一个很小的触发事件,但无法运行,总提示错误 在TextBox2处提示——无法将类型“string”隐式转换为“bool”(第10行) string connection = "Data Source=PC-20110317UBTG;Initial Catalog=Login;Integrated Security=true";
SqlConnection con = new SqlConnection(connection);
con.Open();
string cmd = "select * from Login where username='" + TextBox1.Text + "'";
SqlDataAdapter adapter = new SqlDataAdapter(cmd,con);
DataSet ds = new DataSet();
int count = adapter.Fill(ds, "table");
if (count>0)
{
if (TextBox2.Text = ds.Tables["table"].Rows[0]["answer"].ToString())
{
Label1.Text = "答案错误,请重新填写!";
}
else
{
Label1.Text = "通过";
}
}
else
{ Label1.Text = "没有这个用户!"; }
SqlConnection con = new SqlConnection(connection);
con.Open();
string cmd = "select * from Login where username='" + TextBox1.Text + "'";
SqlDataAdapter adapter = new SqlDataAdapter(cmd,con);
DataSet ds = new DataSet();
int count = adapter.Fill(ds, "table");
if (count>0)
{
if (TextBox2.Text = ds.Tables["table"].Rows[0]["answer"].ToString())
{
Label1.Text = "答案错误,请重新填写!";
}
else
{
Label1.Text = "通过";
}
}
else
{ Label1.Text = "没有这个用户!"; }
少了个=
是==if (TextBox2.Text == ds.Tables["table"].Rows[0]["answer"].ToString())
两个才是比较是否相等