我正在做一个项目,我需要为学校网站制作 VLE 系统。我正在使用 Visual Web Developer 2008、C# 和 SQL 数据库。我需要做的是,当学生使用他们的用户名和密码登录时,他们应该从数据库中显示他们的特定信息(比如 SQL 中的课程名称、学生 ID、电子邮件和姓名等)我已经创建了登录页面:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
con.Open();
string cmdStr = "select count (*) from Registration where UserName ='" + TextBox1.Text + "'";
SqlCommand checkuser = new SqlCommand(cmdStr, con);
int temp = Convert.ToInt32(checkuser.ExecuteScalar().ToString());
if (temp == 1)
{
String cmdStr2 = "select password from Registration where UserName ='" + TextBox1.Text + "'";
SqlCommand pass = new SqlCommand(cmdStr2, con);
String password = pass.ExecuteScalar().ToString();
con.Close();
if (password == TextBox2.Text)
{
Session["New"] = TextBox1.Text;
Response.Redirect("secure.aspx");
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid Password....!!!";
}
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid UserName....!!!";
}
}