Hii
Im always getting the invalid user and password message eventhough it is valid. Please suggest me if there any error in this code.
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection cn = new SqlConnection("Data Source= MINDTECH4; Initial Catalog=suma; User Id=trainee; Password=trainee123");
cn.Open();
SqlCommand cmd = new SqlCommand("select LoginId, Password from memberlogin where LoginId='" + txtlogin + "' and Password='" + txtpwd + "'", cn);
SqlDataReader dr = cmd.ExecuteReader();
string login = txtlogin.Text;
string pwd = txtpwd.Text;
while (dr.Read())
{
if ((dr["LoginId"].ToString() == login) && (dr["Password"].ToString() == pwd))
{
MessageBox.Show("welcome");
}
else
{
MessageBox.Show("userid and password are invalid");
}
}
dr.Close();
cn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
and also help me how to implement the validations in C# code with example.
Thanks
sumasri