Jim Brad
Jim Brad

Reputation: 393

store query data in variables

I would like to know how I could loop over the query below and store values in different variable the table below shows us the data which is output in the query and would lie to store each of the values in 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(),
                             });

Upvotes: 1

Views: 133

Answers (2)

Nick
Nick

Reputation: 4212

did you try with

queryAD1.sortByColumn
queryAD1.numberOfRow
queryAD1.columnsInExcel

Upvotes: 0

Daniel Kelley
Daniel Kelley

Reputation: 7747

Is this what you mean?

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

    //do something with the variables...
}

Upvotes: 2

Related Questions