如何使用Linq Lambda表达式在标签上打印记录 [英] how to print record on label using Linq Lambda expression
本文介绍了如何使用Linq Lambda表达式在标签上打印记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//我为Lambda表达式新推出并推出它
// i m new for for Lambda expression and lurning it
var getdata = dm.Cloths.Where(w => w.Cloth_No == txtvalue).Select(w => new { w.Cloth_Name, w.Cloth_Type });
if (Enumerable.Count(getdata) > 0)
{
MessageBox.Show(????????);
// how can i print Cloth_Name and Cloth_Type in message box which are in getdata
}
推荐答案
你想要制定一点不同的东西,而且你有一个错字。假设您要保留此方法的匿名对象列表将起作用::
You want to formulate that a bit differently, and you have a typo. Assuming that you want to keep the list of anonymous objects around this method will work::
var getdata = dm.Cloths.Where(w => w.Cloth_No == txtvalue).Select(w => new { w.Cloth_Name, w.Cloth_Type }).ToList();
if (getdata.Any())
{
var sb = new StringBuilder();
foreach(var item in getdata)
{
sb.Append(item.Cloth_Name + " : " + item.Cloth_Type + "\n");
}
MessageBox.Show(sb.ToString());
}
错误:更改此: Enumerable.Count(getdate)> 收件人:可枚举。计数(getdata)>
您可能还想执行使用Linq中的新建将其转换为可用列表的查询投影:
var getdata = dm.Cloths.Where(w => w.Cloth_No == txtvalue)。选择(w => new {w.Cloth_Name,w.Cloth_Type})。ToList ();
在if语句上放置一个断点,并且,当你的应用程序停在那里时:检查'getdata的内容:getdata中有什么内容可用可以在MessageBox中显示,必要时转换为String。
'dmCloths是一个类的集合?
Bug: change this: Enumerable.Count(getdate) > To: Enumerable.Count(getdata) >
You may also want to execute the query projection you build using 'new in Linq to transform it into a usable List:
var getdata = dm.Cloths.Where(w => w.Cloth_No == txtvalue).Select(w => new { w.Cloth_Name, w.Cloth_Type }).ToList();
Put a break-point on the if statement, and, when your application stops there: inspect the contents of 'getdata: whatever is available inside 'getdata is available for you to show in a MessageBox, converting to String if necessary.
'dmCloths is a collection of a Class ?
这篇关于如何使用Linq Lambda表达式在标签上打印记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文