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

Hiren SoniRank #694 · 3.5K reputationPosted Feb 18, 2010, 7:02 AM EST
Reader.GetValue(0).Tostring();
Raaj KumarRank #7,836 · 233 reputationPosted Feb 18, 2010, 7:02 AM EST
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
Nainil148 reputationPosted Feb 18, 2010, 7:04 AM EST
Farrukh Javeid38 reputationPosted Feb 18, 2010, 7:23 AM EST
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!