C# LinqToSql…无数据查询
我用Linq构建了这个查询,如下所示C# LinqToSql…无数据查询,c#,.net,linq-to-sql,C#,.net,Linq To Sql,我用Linq构建了这个查询,如下所示 var query15 = (from g in dc.Fix_Hotel_TTVs from f in dc.Hotel_Meals_TBLs where g.CityCode == "KEP" && g.MarketID == "IT" && g.Category == "DEL" && g.HotelCodeID == f.HotelCodeID
var query15 = (from g in dc.Fix_Hotel_TTVs
from f in dc.Hotel_Meals_TBLs
where g.CityCode == "KEP" && g.MarketID == "IT" && g.Category == "DEL" && g.HotelCodeID == f.HotelCodeID
select new { Code3 = f.WholeCode == ""? "No Data" : f.WholeCode, Hotel3 = f.HotelName == "" ? "No Data" : f.HotelName }).DefaultIfEmpty();
如果查询结果在Code3和Hotel3字段中为空,那么我想在DataGrid中显示字符串=“无数据”,但我无法找到获得此结果的解决方案,那么您知道如何解决此问题吗
谢谢,
Jay我认为在SQL查询中硬编码UI常量不是一个好主意。只需在UI中处理这种情况。即,您应该在数据访问层中有查询:
var query = from g in dc.Fix_Hotel_TTVs
join f in dc.Hotel_Meals_TBLs // you can use join
on g.HotelCodeID equals f.HotelCodeID
where g.CityCode == "KEP" &&
g.MarketID == "IT" &&
g.Category == "DEL"
select new FooViewModel { // Consider to create class for this data
Code3 = f.WholeCode,
Hotel3 = f.HotelName
};
然后将从数据访问层返回的数据绑定到DataGrid。还提供默认行,其中包含无数据
文本,如以下问题所述:
var query = from g in dc.Fix_Hotel_TTVs
join f in dc.Hotel_Meals_TBLs // you can use join
on g.HotelCodeID equals f.HotelCodeID
where g.CityCode == "KEP" &&
g.MarketID == "IT" &&
g.Category == "DEL"
select new FooViewModel { // Consider to create class for this data
Code3 = f.WholeCode,
Hotel3 = f.HotelName
};
然后将从数据访问层返回的数据绑定到DataGrid。还提供默认行,其中包含无数据
文本,如以下问题所述:
public class HotelGridViewModel
{
public string Code3{get;set;}
public string Hotel3{get;set;}
}
var query15 = (from g in dc.Fix_Hotel_TTVs
from f in dc.Hotel_Meals_TBLs
where g.CityCode == "KEP" && g.MarketID == "IT" && g.Category == "DEL" && g.HotelCodeID == f.HotelCodeID
select new HotelGridViewModel() { Code3 = f.WholeCode, Hotel3 = f.HotelName
).DefaultIfEmpty(new HotelGridViewModel(){ Code3 = "No Data", Hotel3 = "No Data"});
您应该为DefaultIfEmpty方法提供默认值:
public class HotelGridViewModel
{
public string Code3{get;set;}
public string Hotel3{get;set;}
}
var query15 = (from g in dc.Fix_Hotel_TTVs
from f in dc.Hotel_Meals_TBLs
where g.CityCode == "KEP" && g.MarketID == "IT" && g.Category == "DEL" && g.HotelCodeID == f.HotelCodeID
select new HotelGridViewModel() { Code3 = f.WholeCode, Hotel3 = f.HotelName
).DefaultIfEmpty(new HotelGridViewModel(){ Code3 = "No Data", Hotel3 = "No Data"});
我认为一个简单的解决方案。。。 例如,我有两个字段名和族: 我的问题是:
var query=(from p in behzad.main_table
select p).toArray();
例如,对查询进行简单解码
for(int i=0;i<query.count();i++){
if (query[i].name=="Empty or Null")`
dt[i]["name"]="your message for show in gridview"
gridview.datasource(dt);
我认为一个简单的解决方案。。。 例如,我有两个字段名和族: 我的问题是:
var query=(from p in behzad.main_table
select p).toArray();
例如,对查询进行简单解码
for(int i=0;i<query.count();i++){
if (query[i].name=="Empty or Null")`
dt[i]["name"]="your message for show in gridview"
gridview.datasource(dt);
TNX是WinForms、WPF还是ASP.NET?@Sergey Berezovskiy…这是WPF的…感谢您的关注!!!这是WinForms、WPF还是ASP.NET?@Sergey Berezovskiy…这是WPF的…感谢您的关注!!!