sde
Well-known member
im trying to create an array of objects without using a collection. [CS]public Object[] GetObjects(string Name)
{
Object[] objects = new Object[] { };
SqlConnection con = new SqlConnection(strCon);
con.Open();
string strSQL = "Select ID from table where Name LIKE%" + xID.ToString() + "%";
SqlCommand cmd = new SqlCommand(strSQL,con);
SqlDataReader reader = cmd.ExecuteReader();
int i = 0;
while(reader.Read())
{
objects = new Object( reader[0].ToString() );
i++;
}
return objects;
}[/CS]
Here is the exception:
How can I do this without pre-defining the size of the array?
{
Object[] objects = new Object[] { };
SqlConnection con = new SqlConnection(strCon);
con.Open();
string strSQL = "Select ID from table where Name LIKE%" + xID.ToString() + "%";
SqlCommand cmd = new SqlCommand(strSQL,con);
SqlDataReader reader = cmd.ExecuteReader();
int i = 0;
while(reader.Read())
{
objects = new Object( reader[0].ToString() );
i++;
}
return objects;
}[/CS]
Here is the exception:
Index was outside the bounds of the array. It gets triggered on the second Read() in the while loop.
How can I do this without pre-defining the size of the array?