Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI, I wrote this function on my DataAccessLayer wroking good but when i call this on login form its show the my MdiForm even username and password is wrong plz someone help me what should i do.when username and password should right then Mdiform should show otherwise again loging form show .

public void Getusernamepassword(Bussinessobject.BO EBO)
{

objconn = new SqlConnection(connectionstring);
if (objconn.State != ConnectionState.Open)
try
{
objconn.Open();
objcommand = new SqlCommand("sp_Getpassword", objconn);
objcommand.CommandType = CommandType.StoredProcedure;
objcommand.Parameters.AddWithValue("@username", EBO.Username);
objcommand.Parameters.AddWithValue("@userpassword", EBO.Userpassword);

reader = objcommand.ExecuteReader(CommandBehavior.CloseConnection );

while (reader.Read())
{
count = 0 + 1;

}

if (count == 1)
{

MessageBox.Show("Your password is correct now enjoy application !!! ....");


return;

}

else if (count== 0)
{

MessageBox.Show(" Please Input right your Username and password plz check your spellings !!!!! ");

return;

}

if (count == 2)
{

MessageBox.Show ("Duplicate Username and Password !!!....");

return;


}


}
catch
{

throw;

}
finally
{
reader.Dispose();
objconn.Close();

}


else
{
MessageBox.Show("Your connection is not Open plz check ConnectionString !!!...");
}

}

This is my login buton coding

C#
private void button1_Click(object sender, EventArgs e)
       {
          Bussinessobject.BO EBO = new Bussinessobject.BO();
            EBO.Username = txtusername.Text;
            EBO.Userpassword = txtPassword.Text;
            Businesslayer.BAL EBAL = new Businesslayer.BAL();
            EBAL.Getusernamepassword(EBO);

          
                this.Hide();
                Masterpage mpage = new Masterpage();
                mpage.Show();
        }
Posted

1 solution

Hey there,

I would suggest following modifications:

Change this definition to return int :
C#
public void Getusernamepassword(Bussinessobject.BO EBO)
like:
C#
public int Getusernamepassword(Bussinessobject.BO EBO)
and return the count that you get after
C#
while (reader.Read())
{
    count = 0 + 1;
}
like return count;
and remove this code
C#
if (count == 1)
{
    MessageBox.Show("Your password is correct now enjoy application !!! ....");
    return;
}
else if (count== 0)
{
    MessageBox.Show(" Please Input right your Username and password plz check your spellings !!!!! ");
    return;
}
if (count == 2)
{
    MessageBox.Show ("Duplicate Username and Password !!!....");
    return;
}
from Getusernamepassword method
and replace these lines
C#
EBAL.Getusernamepassword(EBO);
                this.Hide();
                Masterpage mpage = new Masterpage();
                mpage.Show();
of button1_Click method with
C#
int count  = EBAL.Getusernamepassword(EBO);
if (count == 1)
{
    MessageBox.Show("Your password is correct now enjoy application !!! ....");
    this.Hide();
    Masterpage mpage = new Masterpage();
    mpage.Show();
    return;
}
else if (count== 0)
{
    MessageBox.Show(" Please Input right your Username and password plz check your spellings !!!!! ");
    return;
}
if (count == 2)
{
    MessageBox.Show ("Duplicate Username and Password !!!....");
    return;
} 


Let me know if it helps.

Azee...
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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