这是为了验证我在数据库里创建的账号表里的数据,账号表里分别有zh,password和isadmin三个列其中isadmin数据类型为bit类型的,我想问的是如何在C#中获得和验证此账户是否具有管理员身份呢,还有就是我在窗口里设置了两个radiButton用了选择用户和管理员的这个该如何判断呢,请高手们看看代码告诉我如何判断.... SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select zh,password from zhb where zh = '" + cmb1.Text.Trim() + " 'and password = '" + CommonOperation.Md5(txt1.Text.Trim()) + "'";
SqlDataReader read = cmd.ExecuteReader();
if (rdbut1.Checked == true)
{
if (read.Read())
{
Confirmation cfn = new Confirmation();
DialogResult d = cfn.ShowDialog();
if (d == DialogResult.OK)
{
MessageBox.Show("你已成功登陆!");
Pass.name = cmb1.Text.Trim();
Pass.UserPWD = CommonOperation.Md5(txt1.Text.Trim());
this.DialogResult = DialogResult.OK;
}
else if (d == DialogResult.Cancel)
{
}
else
{
MessageBox.Show("验证码错误!");
}
}
else
{
MessageBox.Show("账号或密码输入错误!");
cmb1.Text = "";
txt1.Text = "";
cmb1.Focus();
return;
}
}
if (rdbut2.Checked == true)
{
if (read.Read())
{
Confirmation cfn = new Confirmation();
DialogResult d = cfn.ShowDialog();
if (d == DialogResult.OK)
{
MessageBox.Show("你已成功登陆!");
Pass.name = cmb1.Text;
this.DialogResult = DialogResult.OK;
}
else if (d == DialogResult.Cancel)
{
}
else
{
MessageBox.Show("验证码错误!");
}
}
else
{
MessageBox.Show("账号或密码输入错误!");
}
}
txt1.Clear();
conn.Close();
}
cmd.CommandText = "select zh,password from zhb where zh = '" + cmb1.Text.Trim() + " 'and password = '" + CommonOperation.Md5(txt1.Text.Trim()) + "'";
SqlDataReader read = cmd.ExecuteReader();
if (rdbut1.Checked == true)
{
if (read.Read())
{
Confirmation cfn = new Confirmation();
DialogResult d = cfn.ShowDialog();
if (d == DialogResult.OK)
{
MessageBox.Show("你已成功登陆!");
Pass.name = cmb1.Text.Trim();
Pass.UserPWD = CommonOperation.Md5(txt1.Text.Trim());
this.DialogResult = DialogResult.OK;
}
else if (d == DialogResult.Cancel)
{
}
else
{
MessageBox.Show("验证码错误!");
}
}
else
{
MessageBox.Show("账号或密码输入错误!");
cmb1.Text = "";
txt1.Text = "";
cmb1.Focus();
return;
}
}
if (rdbut2.Checked == true)
{
if (read.Read())
{
Confirmation cfn = new Confirmation();
DialogResult d = cfn.ShowDialog();
if (d == DialogResult.OK)
{
MessageBox.Show("你已成功登陆!");
Pass.name = cmb1.Text;
this.DialogResult = DialogResult.OK;
}
else if (d == DialogResult.Cancel)
{
}
else
{
MessageBox.Show("验证码错误!");
}
}
else
{
MessageBox.Show("账号或密码输入错误!");
}
}
txt1.Clear();
conn.Close();
}
这是为了验证我在数据库里创建的账号表里的数据,账号表里分别有zh,password和isadmin三个列其中isadmin数据类型为bit类型的,我想问的是如何在C#中获得和验证此账户是否具有管理员身份呢,
你应该有管理员的帐号吧,你把此帐号同数据库里管理员的帐号去匹配,如果有的话就是管理员,或者你再加一个字段,标识是管理员还是用用户,当帐户登陆时获取一下此字段的值,看是管理员还是用户.