这段代码有什么问题? [英] What wrong in this code ?

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

问题描述

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");
            
        }
        
    }
}

推荐答案

您的 DataSet new 关键字引用,并且其中没有任何数据。所以如果你在那里放一个断点,经过调试后你可能 null value。

还有一件事,我不知道是什么 ea.selectuserdata()正在返回,我的意思是它必须是数据库操作但是它选择数据的用户是什么?



所以用这种方式修改你的代码,(你可以根据应用程序的性质稍后修改它)

Your DataSet is referenced with new keyword and it doesn't have any data within it. So if you put a breakpoint over there, after debugging it you might null value.
And one thing as well, I don't know what ea.selectuserdata() is returning, I mean it must a database operation but for which user it is selecting data ?

So modify you code this way, (you can alter it later, as per the nature of the application)
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


您需要提供更多信息。你期望发生什么?怎么了?你得到了什么错误?



但是我要告诉你的第一项是MsgBox不适用于网络表单。这适用于Windows应用程序。
You need to provide more information. What do you expect to happen? What is happening? What errors are you getting?

But first item I will tell you is that MsgBox does not work on web forms. That is for windows apps.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆