C# .NET - Arrays inside of ArrayLists Question

Asked By Robbe Morris on 24-Sep-01 11:01 AM
If I am storing a string array inside of 
each element of an ArrayList, how can I 
retrieve a reference to the array 
while iterating through the ArrayList? 

I know the following is incorrect, 
can you provide the proper syntax for 
referencing the arrays for each element 
in the arraylist? 

foreach (object oArray in sArrayList) 

I figured it out... - Asked By Robbe Morris on 24-Sep-01 11:58 AM

I knew this couldn't be that hard.  The following prints out the first element in each array.

  foreach (string[] oArray in sRS) 

Datareader - Asked By Dexter Dotnetsky on 24-Sep-01 01:40 PM

You know the DataReader class supports not only the Page.DataBind method to asp:controls on the page but also has an intrinsic GetString method. It doesn't have all the serialization metadata the DataSet has. So instead of messing with Arraylists you could maybe just concatenate with GetString(rownumber) into a StringBuilder and then spit it out. but the asp:DataGrid control is my favorite.

Pretty similar to what I ended up doing... - Asked By Robbe Morris on 24-Sep-01 02:06 PM

public int ADOGetArray(SqlConnection oConn,string sSQL, ArrayList sRS) 
 int nRetVal = 0;
 string [] sTmpRec=null;
  SqlCommand oCmd = new SqlCommand(sSQL,oConn);
  SqlDataReader oReader = oCmd.ExecuteReader();
  int nCols = oReader.FieldCount; 

  while (oReader.Read())
   nRetVal = 1;
   sTmpRec = new string[nCols];
   for (int nCol=0;nCol<nCols;nCol++) 
     { sTmpRec[nCol] = oReader.GetValue(nCol).ToString(); }

catch (Exception e) { nRetVal = 2; Response.Write(e.Message);} 
return nRetVal;