当前位置: 代码迷 >> ASP.NET >> 江湖救急今天要交!麻烦各位帮上小忙,真是急死了。
  详细解决方案

江湖救急今天要交!麻烦各位帮上小忙,真是急死了。

热度:2483   发布时间:2013-02-25 00:00:00.0
江湖救急啊~今天要交!!麻烦各位帮下小忙,真是急死了。。
第2个if语句中老是不执行,就跳到ELSE中,如果不要第二个if语句旧能进聊天室,可是这样竟不去管理页面,要的话,点进入聊天室按钮一直就像在刷屏,悲催的一直在登陆页面~真是2012.6.18要交啊。。帮帮学生妹子吧!!大侠们~[color=#FF0000][/color]
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{

  protected void Page_Load(object sender, EventArgs e)
  {
  this.Title = "请登录";
  UserName.Focus();
  }
   
  protected void UserLogin_Click(object sender, EventArgs e)
  {
  if (UserName.Text == "" || Password.Text == "")
  {
  Response.Write("<script language=javascript>alert('请输入完整的登录信息!');</script>");
  return;
  }
   
  using (OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["db1ConnectionString"].ToString()))
  try
  {
  con.Open();
  string sql = "select * from tbUser where Username='" + UserName.Text + "'and Password='" + Password.Text + "'";
  OleDbCommand cmd = new OleDbCommand(sql, con);
  using (OleDbDataReader re = cmd.ExecuteReader())
  {
  string name = string.Empty;
  string pwd = string.Empty;
  string nick = string.Empty;
  Int32 power = 0;
  while (re.Read())
  {
  Session["name"] = re["Username"].ToString();
  Session["nick"] = re["Nick"].ToString();
  Session["pwd"] = re["Password"].ToString();
  Session["power "] = Int32.Parse(re["Power"].ToString());
  }

  if (name.Trim() == UserName.Text.Trim() && pwd.Trim() == Password.Text.Trim())
{
if (power == 1) //power == 1,管理员登陆;为0为普通用户登陆
{
Response.Redirect("../聊天室/admin/main.aspx");
}

else
{
Response.Redirect("../聊天室/chat.htm");
}
} }
  }
  catch (Exception ex)
  {
  throw;
  }
  }
  protected void NewUser_Click(object sender, EventArgs e)
  {
  Response.Redirect("../聊天室/zhuce.aspx");
  }
   
}

------解决方案--------------------------------------------------------
大侠都很忙的,只有我这种小菜才有时间的。。。
这样改下
C# code
using System;using System.Collections;using System.Configuration;using System.Data;using System.Data.OleDb;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;public partial class Default2 : System.Web.UI.Page{    static bool Passcheck=false;    void CheckUserName()    {        OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["db1ConnectionString"].ToString());        con.Open();        string sql = "select * from tbUser where Username='" + UserName.Text + "'";        OleDbCommand cmd = new OleDbCommand(sql, con);        OleDbDataReader re = cmd.ExecuteReader();        if (re.Read())        {            Passcheck = false;        }        else        {            Passcheck = true;        }        re.Close();        con.Close();    }    protected void Page_Load(object sender, EventArgs e)    {        this.Title = "新用户注册";    }    protected void zhuce_Click(object sender, EventArgs e)    {        //先调用下CheckUserName方法        this.CheckUserName();        if (Passcheck)        {            OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["db1ConnectionString"].ToString());            string val = "'" + UserName.Text + "','" + "'" + Pass1.Text + "','" + "'" + Nick.Text + "'";            string sql = "insert into tbUser(UserName,Password,Nick)values(" + val + ")";            OleDbCommand cmd = new OleDbCommand(sql, con);            con.Open();            int result = cmd.ExecuteNonQuery(); //这里有问题。。            if (result > 0)            {                Response.Write("<script language=javascript>alert('注册成功,请单击“返回”进入登录页面');</script>");            }            else            {                Response.Write("<script language=javascript>alert('注册失败,请重新注册');</script>");            }        }        else        {            Response.Write("<script language=javascript>alert('用户名已被占用,请选择其他名称!')</script>");        }            }    protected void Return_Click(object sender, EventArgs e)    {        Response.Redirect("../聊天室/Default.aspx");    }}
  相关解决方案