This method read the Database and Returns the Username and Password. tblPassword has only one user name and a password.

            using (SqlConnection dataConnection = new SqlConnection("Data Source=isukoon-pc\\sqlexpress;Initial Catalog=AdsManager;Integrated Security=True"))
            using (SqlCommand dataCommand =
                    new SqlCommand("select username from tblPassword", dataConnection))
            using (SqlCommand data2Command =
                    new SqlCommand("select password from tblPassword", dataConnection))
            {

                dataConnection.Open();
                Uname = Convert.ToString(dataCommand.ExecuteScalar());
                Pword = Convert.ToString(data2Command.ExecuteScalar());
            }        

Then I compare those two values with textbox values.

if (textboxusername.Text == Uname && textboxpwd.Text == Pword)
            {

                var form = new MasterAds();
                form.Show();
                this.Hide();
            }

This is not worked for me. Even I had used

String.Compare();

and got the same result. I even used

MessageBox.Show(Uname);
MessageBox.Show(Pword);

It clearly shows the correct Uname and the Pword too.

try inserting a breakpoint on that line.

Breakpoint-> if (textboxusername.Text == Uname && textboxpwd.Text == PWord)

Then check the value of textboxusername.Text and Uname by right clicking and adding a quick watch. You can then copy the two values over to something like notepad and see if there are any significant differences.

@ddanbe : Thankx mate. I fixed it using Trim() method. @Fenrir : I found it by using ur method.

This question has already been answered. Start a new discussion instead.