Re: Convert a dataset to an array

From: Alvin Bruney [MVP] (vapor)
Date: 03/15/04


Date: Mon, 15 Mar 2004 08:41:00 -0600

I'm not trying to serialize. I'm trying to load data into a component. The
component accepts 1D arrays. The data source is a dataset. I'd like to put
the two together elegantly.

-- 
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:u4J1NImCEHA.3132@TK2MSFTNGP11.phx.gbl...
> Hi Alvin,
>
> I am not sure what you are after.
> DataSet can be serialized (always as XML).
> A better result you will achieve by using this stuff:
> True Binary Serialization And Compression of DataSets
> http://www.eggheadcafe.com/articles/20031219.asp
>
> -- 
> Miha Markic [MVP C#] - RightHand .NET consulting & software development
> miha at rthand com
> www.rthand.com
>
> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> news:%23ywtOMlCEHA.1588@tk2msftngp13.phx.gbl...
> > Surely, there must exist an elegant way to flatten a dataset into a 1D
> > array. I cannot believe that the only way accomplish this is to loop
thru
> > the rows in the dataset. Yuck!!!
> >
> > This is what i tried
> > DataSet ds = loadData();
> > ds.Tables[0].Rows.CopyTo(str,0);   //bombout here
> >
> > next...
> >
> > DataColumnCollection dc = ds.Tables[0].Columns;
> > string[] columns = new string[dc.Count];
> > dc.CopyTo(columns, 0);             //bombout here
> > strHead = String.Join(",", columns);
> >
> > I believe the bombout is because of the system.dbnull which a dataset
> allows
> > however, i'm not sure. I'd like to use one of these approaches. I
> absolutely
> > hate this
> > for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
> >     StringBuilderVal.Append(",").Append( blah blah blah Yuck!!!
> >
> > private DataSet loadData()
> > {
> >    DataSet dsTemp = new DataSet();
> >    DataTable Tables = new DataTable();
> >    dsTemp.Tables.Add(Tables);
> >    dsTemp.Tables[0].Columns.Add( "test", System.Type.GetType(
> > "System.String" ) );
> >
> >    for(int col = 0; col < 10; col++)
> >    {
> >         DataRow myRow = dsTemp.Tables[0].NewRow();
> >         myRow[0] = col.ToString();
> >         dsTemp.Tables[0].Rows.Add(myRow);
> >    }
> >    return dsTemp;
> > }
> >
> > Anybody?
> >
> > -- 
> > Regards,
> > Alvin Bruney [ASP.NET MVP]
> > Got tidbits? Get it here...
> > http://tinyurl.com/3he3b
> >
> >
>
>


Relevant Pages

  • Re: problems returning ArrayList from webServices
    ... - Collections are always serialized as simple arrays. ... If you want to serialize as a specific collection class rather than just an ... On the client side, ... > instead of return an ArrayList object, ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: A neat trick to serialize arrays and hashes
    ... The serialized string will most likely contain ... This technique only handles simple arrays and hashes. ... > an array of these serialized arrays, ...
    (comp.lang.perl.misc)
  • Re: passing Multidimensional array thru the URL
    ... Check out serialize() and unserialize(): ... They basically let you take any type of variable (objects, arrays, ... etc....but not resource handles) and turn them into a string. ...
    (comp.lang.php)
  • Re: A neat trick to serialize arrays and hashes
    ... This technique only handles simple arrays and hashes. ... > lists of lists, ... > an array of these serialized arrays, ...
    (comp.lang.perl.misc)