新人求助 用户验证 但是返回的总是MessageBox.Show("error")
private void button3_Click(object sender, EventArgs e)
{
if (login())
{
MessageBox.Show( "ok ");
}
else {
MessageBox.Show( "error ");
}
}
public bool login()
{string connString = @ "
server=U-UQVSSCFJKQ4JP;
integrated security=sspi;
database=公交;
";
string sql = @ "select * from admin ";
SqlConnection conn = new SqlConnection(connString);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader read = cmd.ExecuteReader();
if (read.Read())
{
if (adminid.Text == read[ "admin "].ToString() && passworld.Text == read[ "passworld "].ToString()) //---与数据库进行比较
{ return true;
}
else
{
return false;