1

我想知道如何遍历下面的查询并将值存储在不同的变量中 下表向我们展示了查询中输出的数据,并将每个值存储在 str1、str2、str3 中

sortByColumn |   numberOfRow  |  coloumnsInExcel
8            |    10          |       10

var queryAD1 = (from m in configurationData.AsEnumerable()
                              where m.Field<String>("QuestionStartText") == question && m.Field<String>("slideNo") == Convert.ToString(slideNumber)
                             group m by m.Field<String>("slideNo") into A123Group
                             select new {
                                 sortByColumn = A123Group.Select(sorted => sorted.Field<String>("SortByColumn")).Distinct(),
                                 numberOfRow = A123Group.Select(sorted => sorted.Field<String>("NoOfRows")).Distinct(),
                                 coloumnsInExcel = A123Group.Select(sorted => sorted.Field<String>("ColumnInExcel")).Distinct(),
                             });
4

2 回答 2

2

你是这个意思吗?

foreach (var query in queryAD1)
{
    str1 = query.sortByColumn;
    str2 = query.numberOfRow;
    str3 = query.coloumnsInExcel;

    //do something with the variables...
}
于 2013-01-29T14:42:45.140 回答
0

你试过了吗

queryAD1.sortByColumn
queryAD1.numberOfRow
queryAD1.columnsInExcel
于 2013-01-29T14:46:30.223 回答