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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Save data on Website 2
Event not firing 6
Error while updating db 2
problem: ds.Tables ["xx"].Columns ["xx"] always returns null 8
Help 2
How its working ?? 1
DataViewHelp 5
system.outofmemory exception 2

Back
Top