Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return all data in one column at once

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
0
0
US
I have been looking for away to retrieve all the data in a data column with out a manual loop. this is what I have come up with.

Code:
DataTable ldtDataTable = new DataTable("Data");
ldtDataTable.Columns.Add("Column1", typeof(String));
ldtDataTable.Columns.Add("Column2", typeof(String));
ldtDataTable.Columns.Add("Column3", typeof(String));
ldtDataTable.Rows.Add(new object[] { "Row1Column1", "Row1Column2", "Row1Column2" });
ldtDataTable.Rows.Add(new object[] { "Row2Column1", "Row2Column2", "Row2Column2" });
ldtDataTable.Rows.Add(new object[] { "Row3Column1", "Row3Column2", "Row3Column2" });
ldtDataTable.Rows.Add(new object[] { "Row4Column1", "Row4Column2", "Row4Column2" });
ldtDataTable.Rows.Add(new object[] { "Row5Column1", "Row5Column2", "Row5Column2" });

var t = (from value in ldtDataTable.AsEnumerable() select value.Field<string>("Column2"));
Array tArray = t.ToArray();
string lstrValues = string.Empty;
Array.ForEach((String[])tArray, z => lstrValues += z + "; ");

OUTPUT

Code:
[green]
Row1Column2; Row2Column2; Row3Column2; Row4Column2; Row5Column2;
[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top