RadioButtonList1与button,lable做用户登录界面的问题?
我在做一个系统,首页上要求是有三个权限,学生,教师和管理员,我用radiobuttonlist设了三个权限,想在button按钮里实现选择任何一个时,登录的界面不一样,代码如下: protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButtonList1.Text = "学生")//运行说这有错误,无法将string转换为bool型。求救,我该怎么改
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "data source=.;database=school;uid=sa;pwd=";
string sql = "select *from [student] where sno='" + TextBox1.Text + "' and sname='" + TextBox2.Text + "'and sdept='"+ TextBox3 .Text +"'and spwd='" + TextBox4.Text + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader dr = null;
conn.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["sname"] = dr["sname"].ToString();
Session["sno"] = dr["sno"].ToString();
Response.Write(" <script>alert('登录成功!');location.href='../student/学主页.aspx' </script>");
}
else
{
Response.Write(" <script>alert('登录信息有误!无法登录!') </script>");
}
}
if(RadioButtonList1 .Text ="教师")
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "data source=.;database=school;uid=sa;pwd=";
string sql = "select *from [teacher] where tno='" + TextBox1.Text + "' and tname='" + TextBox2.Text + "'and tdept='" + TextBox3.Text + "'and tpwd='"+TextBox4 .Text +"'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader dr = null;
conn.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Write(" <script>alert('登录成功!'); </script>");
}
else
{
Response.Write(" <script>alert('登录信息有误!无法登录!') </script>");
}
}
if(RadioButtonList1 .Text ="管理员")
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "data source=.;database=school;uid=sa;pwd=";
string sql = "select *from [admin] where ano='" + TextBox1.Text + "'and ananme='"+ TextBox2 .Text +"'and adept='"+ TextBox3 .Text + "' and apwd='" + TextBox4.Text + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader dr = null;
conn.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Write(" <script>alert('登录成功!'); </script>");
}
else
{
Response.Write(" <script>alert('登录信息有误!无法登录!') </script>");
}
}