Debug your code ...
int tindex=0;
TextBox[] rst = new TextBox[tindex];
rst has only one element at index 0. Edit: My bad see Solution 1 "That declares an array which can hold precisely zero elements".
Then you do
while (sub.Read())
{
tindex++;
try
{
rst[tindex] = new TextBox();
tindex
now has a value of 1 but
rst[1]
does not exist.
Arrays are only good for when you know how big they are going to be, and often not even then. As @User-14699738 suggests, a List would be better in this case. See this article
When to Use Generic Collections | Microsoft Docs[
^]
e.g. (not tested or compiled and very simplistic)
List<TextBox> rst = new List<TextBox>();
TextBox t = new TextBox();
t.Location = new Point(120, startingpoint);
t.Name = string.Format("textBoxf{0}", tindex);
rst.Add(t);
panel7.Controls.Add(t);
In fact, given that you are adding each of the textboxes to the panel7 control, why not just use that Control collection. There appears to be no need for the array (or List) in the code you have shared