主题:程序无错但是无办法跳转!请帮忙!在线等!
private bool checkUser(string userName,string userPwd)
{
userName=TextBox1.Text;
userPwd=TextBox2.Text;
string sqlconn="server=(local);uid=sa;pwd=;database=Text1";
SqlConnection myConnection=new SqlConnection(sqlconn);//打开数据库连接
myConnection.Open();
SqlCommand myCommand=new SqlCommand("Select * from test1 where UserName='"+userName+"' and UserPassword='"+userPwd+"'",myConnection);
SqlDataReader myReader=myCommand.ExecuteReader();
if(myReader.Read())
{checkLevel(myReader.GetString(2));
myReader.Close();
myConnection.Close();
return true;//登陆成功
}
else
{
myReader.Close();
myConnection.Close();
return false;//登陆失败
}
private void checkLevel(string flag)
{
if(flag=="总经理")
{
Response.Redirect("WebForm3.aspx");
}
if(flag=="经理")
{
Response.Redirect("WebForm2.aspx");
}
if(flag=="员工")
{
Response.Redirect("WebForm4.aspx");
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(checkUser(TextBox1.Text,TextBox2.Text))
{
Response.Write("<script>alert('登陆成功!')</script>");
}
if(TextBox1.Text!="UserName" && TextBox2.Text!="UserPassword")
{
Response.Write("<script>alert('登陆失败!')</script>");
}
}
//程序能够执行。但是。当我输入数据库中匹配的内容的时候。页面会显示:“登陆成功”然后又接着显示“登陆失败!”;
以上程序我在别处能完整的执行。先更换地方后不行了!哭死!
在线等!!!
{
userName=TextBox1.Text;
userPwd=TextBox2.Text;
string sqlconn="server=(local);uid=sa;pwd=;database=Text1";
SqlConnection myConnection=new SqlConnection(sqlconn);//打开数据库连接
myConnection.Open();
SqlCommand myCommand=new SqlCommand("Select * from test1 where UserName='"+userName+"' and UserPassword='"+userPwd+"'",myConnection);
SqlDataReader myReader=myCommand.ExecuteReader();
if(myReader.Read())
{checkLevel(myReader.GetString(2));
myReader.Close();
myConnection.Close();
return true;//登陆成功
}
else
{
myReader.Close();
myConnection.Close();
return false;//登陆失败
}
private void checkLevel(string flag)
{
if(flag=="总经理")
{
Response.Redirect("WebForm3.aspx");
}
if(flag=="经理")
{
Response.Redirect("WebForm2.aspx");
}
if(flag=="员工")
{
Response.Redirect("WebForm4.aspx");
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(checkUser(TextBox1.Text,TextBox2.Text))
{
Response.Write("<script>alert('登陆成功!')</script>");
}
if(TextBox1.Text!="UserName" && TextBox2.Text!="UserPassword")
{
Response.Write("<script>alert('登陆失败!')</script>");
}
}
//程序能够执行。但是。当我输入数据库中匹配的内容的时候。页面会显示:“登陆成功”然后又接着显示“登陆失败!”;
以上程序我在别处能完整的执行。先更换地方后不行了!哭死!
在线等!!!