newbie needs help with code

  • Thread starter Thread starter Raymond Du
  • Start date Start date
R

Raymond Du

Hi,

I have a SqlDataReader object, say the name is dr1, it has only one column,
say its name is "Name", how do I convert dr1 to an array of Strings, i.e.
String[].

Thanks in Advance
 
You can't just convert, you'll have to build the array. IIRC you would have
to may 2 passes of the data.

Try this instead

System.Data.SqlClient.SqlDataReader reader = ** get the reader first **;
System.Collections.Specialized.StringCollection sc = new
System.Collections.Specialized.StringCollection();
while ( reader.Read() )
{
if ( reader[0] != DBNull.Value )
sc.Add(reader[0].ToString());
}

string[] s = new string[sc.Count];
sc.CopyTo(s, 0);



HTH
Brian W
 
Back
Top