Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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:
SQL
var ST= (from obj in dbEntity.Myname_TTL
                              where obj.myName == MyNAME 
                              select obj.myName).ToList();

if (ST== 0)
{}
else
{}

But ST is not getting values, Can u please help me in this regarding.
Posted
Updated 20-May-14 12:22pm
v3
Comments
ZurdoDev 20-May-14 16:45pm    
Aren't you already doing it? You have where obj.myName == MyNAME. So, put the debugger and evaluate ST after it runs.
apr1234 20-May-14 16:59pm    
Yes, I am doing it. But i am little confused how to get the values from the query and try to compare with the zero. Can you let me know how to do it...
Emre Ataseven 20-May-14 17:29pm    
what is the type of dbEntity, Myname_TTL?
apr1234 21-May-14 11:06am    
Thank you!!

C#
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
C#
if(ST.Any())
{
   // there are matching items, do something ...
}else
{
  // no matching items 
}
 
Share this answer
 
Comments
apr1234 21-May-14 11:06am    
Thank you!!
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
 
Share this answer
 
Comments
apr1234 20-May-14 16:38pm    
OriginalGriff : okay then how I need to get the value from the linq query and store it in the variable and make some calculations?
Thanks for the reply!!
apr1234 21-May-14 11:06am    
Thank you OriginalGriff!!
if(((from obj in dbEntity.Myname_TTL where obj.myName == comboBox1.SelectedText  select obj.myName).ToList().Count())>0);
            {
            }
          else
            {
            }


Here u can use the linq query to find the count of the result expression which is immediately executed
Combobox1 be the name of your combobox you can use the selected text, or value property for your linq where condition
 
Share this answer
 
Comments
apr1234 21-May-14 10:49am    
Thank you very much balajidileepKumar!!!
I really appreciate for the help you have done.. As a beginner to entity frame work I am getting some doubts and trying to resolve them...

Once again thank you!!
See code using Equaql()
var ST = (from obj in dbEntity.Myname_TTL
                   where obj.myName.ToLower().Equals(MyNAME.ToLower())
                   select obj.myName).ToList();

         if (ST == 0)
         { }
         else
         { }
 
Share this answer
 
Comments
apr1234 21-May-14 11:06am    
Thank you!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900