在IF语句中运行查询

时间:2017-06-09 09:09:25

标签: c# vb6

我试图学习C#并遇到了一个问题,我希望你们能够知道一个简单的解决方案。

我想运行两个可能的LINQ查询,但是从不同的地方读取并根据IF条件返回2个不同的字段(都是id' s)。

在VB6中,它可能很简单:

Dim strQuery as string
Dim rs as adodb.recordset

If 1 = 1 then
    strQuery = "Select messageid as id1, refid as id1 from x where ..."
else
    strQuery = "Select commonid as id1, nextid as id2 from x where ..."
endif

set rs = cn.execute(strquery)

debug.print rs!id1 & rs!id2

如何在c#中完成?

我试过了:                 IQueryable fD = null;

            if (1 == 1)
            {
                fD = from qa in data.table1
                        select qa;
            }
            else
            {
                fD = from qa in data.table2
                        select qa;
            }

            foreach (var a in FD)
            {
                // Unable to see any data.
            }

1 个答案:

答案 0 :(得分:0)

谢谢山下哲也指出我正确的方向 IQueryable strQuery

          foreach (**dynamic** a in strQuery)
            {
                //a.CentralContractorID
            }

动态是缺少的词,它现在完美无缺。

相关问题