请问有人可以帮忙吗?我需要返回一个表,其中Extn_In_Call_Records = Extn_Number,如果任何一边不匹配,仍然返回一个值,就像SQL的全外连接。我花了几个小时看这个问题,但是无法使它工作!! 如果我移除union,我可以让下面的代码工作,但是它只返回匹配的结果。Datatable是从MYSQL中填充的。任何帮助都将是伟大的。
//Full Table
DataTable fullext = new DataTable();
fullext.Columns.Add("Extn_In_Call_Records", typeof(string));
fullext.Columns.Add("Total_Calls", typeof(int));
fullext.Columns.Add("Extn_Number", typeof(string));
fullext.Columns.Add("Phys_Switch_Name", typeof(string));
//End Full Table
try
{
//Full Result
var result = from callrc in callrecdt.AsEnumerable()
join physex in physextns.AsEnumerable()
on callrc["Extn_In_Call_Records"] equals physex["Extn_Number"]
.Union
from physex in physextns.AsEnumerable()
join callrc in callrecdt.AsEnumerable()
on physex["Extn_Number"] equals callrc["Extn_In_Call_Records"]
select fullext.LoadDataRow(new object[] {
callrc["Extn_In_Call_Records"],
callrc["Total_Calls"],
physex["Extn_Number"] == null ? "" : physex["Extn_Number"],
physex["Phys_Switch_Name"] == null ? "" : physex["Phys_Switch_Name"]
}, false);
result.CopyToDataTable();
fullresult.DataSource = fullext;
查看结果
Extn_In_Call_Records Total_Calls Extn_Number Phys_Switch_Name
null 20 0 Hospital
null 310 1 Hospital
4 132 4 Hospital
2004 null null Hospital
2006 2 2006 Hospital