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!
Loading
Farrukh JaveidPosted Feb 18, 2010, 12:23 PM
Thanks for the response, the problem has been resolved. But still i cant understand how come it worked for another program and presented an exception for this one!
Thanx Again!
NainilPosted Feb 18, 2010, 12:04 PM
Raaj KumarPosted Feb 18, 2010, 12:02 PM
I guess the problem is in reader.GetValue(1).ToString(). Put a break point here and try executing this statement with quick watch. Verify that you are getting the right column.
Regards,
Raaj
Hiren SoniPosted Feb 18, 2010, 12:02 PM
Reader.GetValue(0).Tostring();