|
-
Jun 18th, 2007, 11:08 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Error when getting data from the database. VWDE/SQL/Asp.Net/C#
I get the error:
Index out of range exception was unhandled by user code.
At the line:
Label4.Text += reader["RelativeLN"].ToString();
The two lines above it:
Label4.Text += reader["Relation"].ToString() + ": ";
Label4.Text += reader["RelativeFN"].ToString();
will read just fine if I comment out that third line. I don't understand why this could be happening. There is data in the db for the RelativeLN column and it has the same data type as the previous two columns.
private void getRelatives()
{
//Define database connection
SqlConnection conn = new SqlConnection(
"Server=localhost\\SqlExpress;Database=MyDB;" + "Integrated Security=True");
//Create command
SqlCommand comm = new SqlCommand("SELECT Relation, RelativeFN FROM RelativeTable WHERE RelativeTable.UserID IN (SELECT UserID FROM UsrTbl WHERE UserName = @usrnmeLbl)", conn);
comm.Parameters.AddWithValue("@usrnmeLbl", usrNmeLbl.Text);
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
Label4.Text += reader["Relation"].ToString() + ": ";
Label4.Text += reader["RelativeFN"].ToString();
Label4.Text += reader["RelativeLN"].ToString();
}
}
I'm hoping someone can provide me some info on what could possibly be going wrong.
Thank you so much in advance.
-
Jun 18th, 2007, 12:28 PM
#2
Thread Starter
Hyperactive Member
Re: Error when getting data from the database. VWDE/SQL/Asp.Net/C#
Solved it. I wasn't selecting that column. Duh...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|