2

我在两个文本框中输入用户名和密码的值。当我单击提交时,我希望表适配器检查数据库以查看这些值是否真的是值并允许用户登录。

这是我的代码:

protected void Submit_Click(object sender, EventArgs e)
{

    //assign text from the textboxes to variables 
    string userName = TextBox1.Text;
    string passWord = TextBox2.Text;

    lblError.Visible = true;

    try
    {

        string passwordValue = Encrypt(passWord);

        DataSet1.tblUserDataTable dataTable = proccessedProcess.Login(userName, passwordValue);

        if (dataTable != null & dataTable.Count!=0)
        {
            DataSet1.tblUserRow dataRow = dataTable[0];
            if (dataRow.nUserID.ToString() == "00000000-0000-0000-0000-000000000000")
            {
                lblError.Text = "";

            }

            else if(dataRow.nUserID.ToString() != "00000000-0000-0000-0000-000000000000")
            {
                Session["CurrentUserID"] = dataRow.nUserID.ToString();
                Session["LoggedIn"] = "YES";
                Session["LastLogin"] = DateTime.Now.ToString();
                Session["UserName"] = dataRow.txtUserName;

                HttpContext.Current.Response.Redirect("MainCustomer.aspx");

            }
        } else {


                lblError.Text = "Incorrect UserID or Password";

            }

    }

    catch (Exception E)
    {
        E.Message.ToString();
        lblError.Text = E.Message;

    }


}
4

1 回答 1

1

在 catch 部分你有 E.Message.ToString(); 这没有效果。您必须将其设置为标签才能查看是否发生异常或抛出 E

catch (Exception E)
{
   // E.Message.ToString();
   Throw;
}
于 2012-09-14T21:00:01.067 回答