I'm trying to figure out the best way to populate an array with numerical values pulled from a database. This is the function I have set up so far:
protected int[] GetBoxes()
{
int[] boxes;
string query = "SELECT DISTINCT Length FROM Products INNER JOIN Baird_Ground_Boxes_Products ON uidBox = ProductId";
using (SqlConnection cn = new SqlConnection(AbleConnectionStr))
{
SqlCommand cmd = new SqlCommand(query, cn);
cmd.CommandType = CommandType.Text;
cn.Open();
using (IDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
if (reader["Length"].ToString() !="")
{
//populate array with the length values returned
}
}
}
}
return boxes;
}
There is never a single set of values that could be returned (could be 3, could be 2). I'm getting confused on how to populate the array, like I'm making it too difficult or something. Any suggestions would be helpful!