Index Outside the bounds of array
Hello,
I have written a code to create the login module of a system. I dont know what is the problem, i have done the exact code before and it worked but this time its giving an exception "Index outside the bounds of array".
The code is
string login = "select Password from UserInfo where Username = "+tbx_username.Text+"'";
conn.Open();
SqlCommand cmd = new SqlCommand(login, conn);
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
if (reader.Read())
{
if (tbx_password.Text == reader.GetValue(1).ToString())
{
MessageBox.Show("welcome " + tbx_username.Text + "");
}
}
else
{
MessageBox.Show("invalid username or password!");
}
conn.Close();
Any urgent help will be very much appreciated!
Regards!