I try this code to display names from database in loop but this shows an error index was outside the bounds of the array meaning on this line name[j++] = Convert.ToString(reader["CategoryName"]);
code
con.Open();
int count =0;
int j =0;
//cmd = new SqlCommand("select * from Category");
string[] name = new string[count];
cmd = new SqlCommand("select CategoryName from Category",con);
reader = cmd.ExecuteReader();
while (reader.Read())
{
name[j++] = Convert.ToString(reader["CategoryName"]);
}
int loc = 37;
CheckBox[] obj = new CheckBox[count];
for (int i = 0; i < count; i++)
{
obj[i] = new CheckBox();
obj[i].Location = new System.Drawing.Point(loc, 50);
obj[i].Size = new System.Drawing.Size(80, 17);
obj[i].Text = name[i];
this.Controls.Add(obj[i]);
loc += 80;
}
con.Close();
any help?