Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
 i am currently trying to design a login page... but looks like i have a problem...  i would appreciate if mistakes are pointed out...
my codes are as follows
    private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet1 dat = new DataSet1();
                DataSet1TableAdapters.usersTableAdapter usr2 = new DataSet1TableAdapters.usersTableAdapter();
                usr2.FillBy(dat.users, textBox1.Text, textBox3.Text);
                string usrnm = dat.users.Rows[0][0].ToString();
                string mode = dat.users.Rows[0][1].ToString();
                string passwrd = dat.users.Rows[0][2].ToString();
                if (usrnm == textBox1.Text && passwrd == textBox3.Text)
                {
                    if (mode == "IndustryMode")
                    {
                    IndustryModePage ind = new IndustryModePage();
                    ind.MdiParent = this;
                    ind.Show();
                    }
                    else if (mode == "HomeMode")
                    {
                        HomeModePage hom = new HomeModePage();
                        hom.MdiParent = this;
                        hom.Show();  }
                }
                else
                {
                    MessageBox.Show("wrong user/password combination");
                }
            }
            catch
            {
                MessageBox.Show("non existing user");
            }
        }
    }
its giving me an error that even my existing users are non existing.
Posted

1 solution

Firstly, when you add a try - catch block you really shouldn't use an anonymous catch - all it does is throw away the cause of the error, so when something like this happens, you don't have any idea what is causing the problem.
Catch the exception, log it, and the report with or without a reason. But don't just throw the error away - that means you have to guess what is causing the problem!
And in this case, guess is all we can do: So I am guessing that you are getting a "Object reference not set to an instance of an object." from one of your dat.users lines - and that dat contains no rows or columns...


BTW: It is a bad idea to report different messages for bad password and bad user - all that does is tell a hacker when he has found a legitimate user and to concentrate on finding a password to match...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900