在登陆界面输入信息后,不跳转界面,也不出现bug,为什么? 以下是login.aspx.cs代码 protected void ButtonLogin_Click(object sender, EventArgs e)
{
string sqlConnectStr = ConfigurationManager.ConnectionStrings["ExamConnectionString"].ConnectionString;
//创建数据库连接,并打开
SqlConnection con = new SqlConnection(sqlConnectStr);
con.Open();
string sqlStr;
if (DropDownListIdentity.SelectedItem.Text == "学生")
sqlStr = "select SNo,SPass from [student]";
else
sqlStr = "select TNo,TPass from [teacher]";
SqlCommand com = new SqlCommand(sqlStr, con);
SqlDataReader reader = com.ExecuteReader();
reader.Read();
//前台后台登陆
if (DropDownListIdentity.SelectedItem.Text == "学生")
{
if ((TextBoxUserName.Text == reader["SNo"].ToString())
&& (TextBoxPass.Text == reader["SPass"].ToString()))
{
Session["Identity"] = "学生";
reader.Close();
con.Close();
Response.Redirect("~/Default.aspx");
}
else Response.Write("<script>alert('用户名或密码错误!')</script>");
}
else if (DropDownListIdentity.SelectedItem.Text == "教师")
{
if ((TextBoxUserName.Text == reader["TNo"].ToString())
&& (TextBoxPass.Text == reader["TPass"].ToString()))
{
Session["Identity"] = "教师";
reader.Close();
con.Close();
Response.Redirect("~/BackMain.aspx");
}
else Response.Write("<script>alert('用户名或密码错误!')</script>");
}
}
}
{
string sqlConnectStr = ConfigurationManager.ConnectionStrings["ExamConnectionString"].ConnectionString;
//创建数据库连接,并打开
SqlConnection con = new SqlConnection(sqlConnectStr);
con.Open();
string sqlStr;
if (DropDownListIdentity.SelectedItem.Text == "学生")
sqlStr = "select SNo,SPass from [student]";
else
sqlStr = "select TNo,TPass from [teacher]";
SqlCommand com = new SqlCommand(sqlStr, con);
SqlDataReader reader = com.ExecuteReader();
reader.Read();
//前台后台登陆
if (DropDownListIdentity.SelectedItem.Text == "学生")
{
if ((TextBoxUserName.Text == reader["SNo"].ToString())
&& (TextBoxPass.Text == reader["SPass"].ToString()))
{
Session["Identity"] = "学生";
reader.Close();
con.Close();
Response.Redirect("~/Default.aspx");
}
else Response.Write("<script>alert('用户名或密码错误!')</script>");
}
else if (DropDownListIdentity.SelectedItem.Text == "教师")
{
if ((TextBoxUserName.Text == reader["TNo"].ToString())
&& (TextBoxPass.Text == reader["TPass"].ToString()))
{
Session["Identity"] = "教师";
reader.Close();
con.Close();
Response.Redirect("~/BackMain.aspx");
}
else Response.Write("<script>alert('用户名或密码错误!')</script>");
}
}
}
解决方案 »
- 类似 where in()
- 点击linkbutton在新窗口中打开,并传递多个参数如何实现?
- post怎么传递不过去啊?
- 在webApplication中创建一个类无法应用data.sqlClient
- 有关在vs2005中连接远程sql2005数据库文件问题
- 一题难倒众人,如何在skin文件中定义detailsview内部的textbox?
- 敬求,从查询结果到内存表的程序。
- 4级级联菜单的问题求助
- ☆☆☆.net做WAP开发。有没有什么劣势??诚恳请各位做过WAP的,给我些意见。☆☆☆
- 怎样设置可以使RegularExpressionValidator在提示出错信息时信息是闪耀的
- 在Web.sitemap中,链接的文件过长,用什么字符进行链接
- js 数组
谢啦
alert(‘失败’);
}代替你的alert
还有就是不要使用response.write来注册客户端js,这样会导致你的页面的样式出现混乱。而是改用clientsript.registescript.............
TextBoxUserName.Text == reader["SNo"].ToString()你的数据库里就一个学生?