![]() |
#2
yunj11052007-03-22 16:22
这是我自己做的,还没调试,你看看能不能用上.也请各位大侠看看是否有错
protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "" || TextBox2.Text == "") { Response.Write("<script defer>alert('请每项都输入!');</script>"); } //下面就是检查是否有这个用户和是否冲突了 else { string strCmd = "select user_name from lab_users where user_ID like'" + TextBox1.Text + "'and password like'" + TextBox2.Text + "'"; SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["labConnectionString"].ConnectionString); SqlCommand myCommand = new SqlCommand(strCmd, myConnection); myCommand.Connection.Open(); string username = (myCommand.ExecuteScalar()).ToString(); myCommand.Connection.Close(); if (username != null) { Session["user_ID"] = TextBox1.Text; Session["user_name"] = username; string strCmd_type = "select user_type from lab_users where user_ID='" + TextBox1.Text + "'"; SqlCommand myCommand1 = new SqlCommand(strCmd_type, myConnection); myCommand1.Connection.Open(); int flag = int.Parse(myCommand1.ExecuteScalar().ToString()); if (flag == 0) { Response.Redirect("Admin.aspx"); } else if (flag == 1) { Response.Redirect("Leader.aspx"); } else if (flag == 2) { Response.Redirect("A_Teacher.aspx"); } else { Response.Redirect("A_Student.aspx"); } } else { Response.Write("<script defer>alert('密码不正确!');</script>"); TextBox1.Text = " "; TextBox2.Text = " "; } |
我是在做检验用户名不要和数据库的用户名冲突的问题,新手,请大峡们帮忙