A
Alvin Bruney [MVP]
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?
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?