我在数据库中有一个表,其中有一列 UserName 和 UserRights。UserRights 是admin
或者现在,如果用于登录的用户名只是一个用户user
,我想禁用另一种形式的一些按钮。login form
我将如何做到这一点?我有以下代码:
private void button1_Click_1(object sender, EventArgs e)
{
connection.Open();
OleDbDataReader reader = null;
OleDbCommand command = new OleDbCommand("select* from TableAcct", connection);
reader = command.ExecuteReader();
while (reader.Read())
{
uname.Add(reader["username"].ToString());
password.Add(reader["userpassword"].ToString());
rights.Add(reader["rights"].ToString());
}
connection.Close();
int totalItems = uname.Count;
int count = 0;
string isValidated = "";
while (count < totalItems)
{
if ((Username.Text == uname[count].ToString()) && (pword.Text == password[count].ToString()))
{
isValidated = "True";
rights2 = rights[count].ToString();
count = 100;
}
else
{
count++;
}
}
if (isValidated == "True")
{
Mainform mainform1 = new Mainform();
login.ActiveForm.Hide();
mainform1.linkLabel1.Text = Username.Text;
mainform1.ShowDialog();
Username.Clear();
pword.Clear();
}
else
{
MessageBox.Show("Invalid Log in. Please try again", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}