0
我想在C#中左连接2个数据表AllTimesTxnTable
和resolvedDt
,其中我希望AllTimesTxnTable中的每一行只有来自resolvedDt的匹配行。2个数据表的左外连接
条件应根据mid
和txndate
最后的同时选择我想中旬txndate从AllTimesTxnTable和txncount从resolvedDt,如果resolvedDt没有记录则0
我尝试以下LINQ的加入查询:
var results = from table2 in AllTimesTxnTable.AsEnumerable()
join table1 in resolvedDt.AsEnumerable()
on new { mid = table2.Field<int>("mid"), txndate = table2.Field<string>("txndate") } equals new { mid = table1.Field<int>("mid"), txndate = table1.Field<string>("txndate") }
into temp
from leftTable in temp.DefaultIfEmpty()
select new
{
MId = (int)table2["mid"],
TxnDate = (string)table2["txndate"],
TxnCount = leftTable["txncount"] == null ? 0M : (decimal)leftTable["txncount"]
};
但它给了我一个错误:Object reference not set to an instance of an object.
同时选择。
没有得到怎么回事错在这里。
你的问题有被关闭作为[this]的重复的危险(http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-doi-i-fix - 它)着名的问题。 –
堆栈跟踪会有帮助吗? –
你至少使用的调试,以确保您所使用的数据表不是空在这一点? –