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.