如何在使用组合框文本值作为输入时获取linq查询输出 [英] how to get linq query output while using combo box text value as input
本文介绍了如何在使用组合框文本值作为输入时获取linq查询输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨伙计......
我有一个combox,我将其值存储到一个变量中..
string MyNAME = MyNameComboBox.Text.ToString();
然后我想根据组合框值从表中获取值:
Hi Folks...
I have a combox and i am storing its value into one variable..
string MyNAME = MyNameComboBox.Text.ToString();
And then I want to get the values from the tables based on the combo box values:
var ST= (from obj in dbEntity.Myname_TTL
where obj.myName == MyNAME
select obj.myName).ToList();
if (ST== 0)
{}
else
{}
但是ST没有获得价值,请你帮帮忙我在这方面。
But ST is not getting values, Can u please help me in this regarding.
推荐答案
var ST= (from obj in dbEntity.Myname_TTL
where obj.myName == MyNAME
select obj.myName).ToList();
// here you have List ST
//to check item count of the list you can use Count
if(ST.Count()>0)
{
// there are matching items, do something ...
}else
{
// no matching items
}
或者您可以使用任何
,如下所示
Or you can use Any
like below
if(ST.Any())
{
// there are matching items, do something ...
}else
{
// no matching items
}
嗯...... ST不是一个整数 - 它是一个集合(因为你把ToList添加到了链接的末尾),所以它不会为零,或为null
Um...ST isn't an integer - it's a collection (because you added the ToList to the end of the Link), so it's not going to be zero, or null
if(((from obj in dbEntity.Myname_TTL where obj.myName == comboBox1.SelectedText select obj.myName).ToList().Count())>0);
{
}
else
{
}
在这里你可以使用linq查询来查找立即执行的结果表达式的计数
Combobox1是你可以使用所选文本的组合框的名称,或者您的linq的值属性,条件
这篇关于如何在使用组合框文本值作为输入时获取linq查询输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文