本文介绍了这段代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class loginpage : System.Web.UI.Page
{
    exploringapplication ea = new exploringapplication();
    DataSet data = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        if (TextBox1.Text == "")
        {
            MsgBox.Show("Enter the UserName");
        }
        if (TextBox1.Text != "")
        {
            if (TextBox2.Text == "")
            {
                MsgBox.Show("Enter the Password");
            }
        }

        if (TextBox1.Text != "" && TextBox2.Text != "")
        {
                data = ea.selectuserdata();
                if (TextBox1.Text == data.Tables[0].Rows[0]["email"].ToString() && TextBox2.Text == data.Tables[0].Rows[0]["dob"].ToString())
                {
                    Response.Redirect("select.aspx");
                }
                else
                    MsgBox.Show("Enter the correct data");

        }

    }
}

推荐答案

public DataTable SelectUserData(string email, string password)
{
string str = "select * from user where email = '" + email + "', password = '" + password + "'" ;
SqlDataAdapter da = new SqlDataAdapter(str, connectionObj);
DataTable dt = new DataTable();
da.Fill(dt);

return dt;
}

protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "")
        {
            MsgBox.Show("Enter the UserName");
        }
        if (TextBox1.Text != "")
        {
            if (TextBox2.Text == "")
            {
                MsgBox.Show("Enter the Password");
            }
        }

        if (TextBox1.Text != "" && TextBox2.Text != "")
        {
               DataTable dt = ea.SelectUserData(TextBox1.Text, TextBox2.Text);

                if(dt.Rows.Count > 0)
                Response.Redirect("SomePage.aspx");
                else
                Response.Redirect("SomeOtherPage.aspx");

        }

    }



-KR


-KR



这篇关于这段代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 01:09