开发者

DataTable's Row's First Column to String Array

开发者 https://www.devze.com 2023-03-08 13:25 出处:网络
I have a DataTable. I want to get every rows first column value and append to a string array. Ido not want to use foreachlooping for 开发者_运维问答every row and adding to string array. I tried this,

I have a DataTable. I want to get every rows first column value and append to a string array. I do not want to use foreach looping for 开发者_运维问答every row and adding to string array. I tried this, but stuck at some point

DataRow[] dr = new DataRow[dtCampaignSubscriberLists.Rows.Count];
dtCampaignSubscriberLists.Rows.CopyTo(dr, 0);
string[] array = Array.ConvertAll(dr, new Converter<DataRow, String>(????));

Thanks


string[] array = yourTable
                 .AsEnumerable()
                 .Select(row => row.Field<string>("ColumnName"))
                 .ToArray();


You could do something like:

dtCampaignSubscriberLists.AsEnumerable().Select(r => r[0].ToString()).ToArray();

0

精彩评论

暂无评论...
验证码 换一张
取 消