I just seem to be losing it today. Can anyone help me find what I’m doing wrong here:
1. for (int y = 0; y < 5; y++)
2. {
3. IDataReader getLineInfo = DB.GetRS("Select LineText From TIF Where SCRID ='" + scRID + "' AND LineNum='" + y + "'");
4. if (getLineInfo.Read())
5. {
6. string[] lineText = new string[y];
7. lineText[y] = (string)getLineInfo["LineText"];
8.
9. ((Label)item.FindControl(string.Format("lbl{0}", y))).Text = "<a href='" + lineText[y] + "' target='_blank'> Link</a>";
10. }
11. getLineInfo.Dispose();
12. getLineInfo.Close();
13. }
I get the error on line 9. I originally had ‘y’ start at 1 because there is no lineNum == 0 .. but I thought since arrays start with 0 I was messing something up there. But that did not fix my problem. If someone can help me see what I’m not it would be greatly appreciated. Also there is no user input on this page cause I know The whole IDataReader using select statements can be bad.
If any additional info is needed I can write it in, and thanks to anyone who can help
Also,
lineTextis created locally inside the loop, you can simply replacestring[] lineTextwithstring lineTextand forget abouty.If you think you need
ythen there is something else wrong/missing in this code.