okay this is what would seem to be a simple problem... but I am stumped. I am taking multiple columns from an sql db and putting into an object array. Then I put all the objects in a string array. I would like to assign each value in the string array to a variable.
private void load_array()
{
/* create connection */
SqlConnection conn = new SqlConnection("Data Source=192.168.168.134\\MSSQLLITMARK;Initial Catalog=Litmark;User id=sa;password=**************;");
SqlCommand cmd = new SqlCommand("SELECT Images_ID FROM tbImages WHERE Images_CarID = @car_id", conn);
cmd.Parameters.AddWithValue("@car_id", car_id);
try
{
/* array list to hold data */
ArrayList list = new ArrayList();
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
object[] values = new object[reader.FieldCount].ToArray();
reader.GetValues(values);
list.Add(values);
}
/* now convert to a string array */
foreach (object[] row in list)
{
string[] details = new string[row.Length];
int columnIndex = 0;
foreach(object column in row)
{
details[columnIndex++] = Convert.ToString(column);
}
/* Assign the itmes in the string array to picture boxes. */
/* I have global variables picID1 - picID5 that I would like to assign the data in string[] */
for (int i = 0; i < details.Length; i++)
{
MessageBox.Show("array : " + details[i]);
}
}
}
catch (Exception ex)
{
MessageBox.Show("error: " + ex.Message.ToString());
}
}