First of all is there any data in the database provided your username & password matches, if yes it should come. I guess you providing the right connection string so its able to open the connection. while debugging check the connection after open, copy the cmd text query & execute in the SQL server. if the data comes then it should come in your application too. it might be you providing wrong data or there is no data in the database which matches with your username & password. try dr[0] & dr[1] instead of dr["id"] & dr["pswd"].
Check this link for more information.[
^]
try this solution. Hope it helps.
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.textBox1.Text) | string.IsNullOrEmpty(this.textBox2.Text))
{
MessageBox.Show("Please Enter Username or Password");
return;
}
SqlConnection conn=new SqlConnection("Data Source=PRANAV\\SQLEXPRESS;Initial Catalog=Try;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM idpswd where id='"+textBox1.Text+"'and pswd='"+textBox2.Text+"'",conn);
System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
if (this.textBox1.Text == dr["id"].ToString() & this.textBox2.Text == dr["pswd"].ToString())
{
MessageBox.Show("Login Successfull!");
}
else
{
MessageBox.Show("Invalid username or password");
return;
}
}
}