I have a pretty basic question but it is doing my nut in!!!!
I have created a variable which checks my data table checks to see if an item using my page control ID already exists. IF it does I then want to warn my user that they have already chosen a page colour!
My question is how do I check if this variable is empty or not!
var qry = from x in db.DT_Control_ColourPalette_PageColors
where x.PageControlID == int.Parse(HF_CPID.Value)
select new
{
x.PageControlID,
};
The argument I think is right?
if (qry !=null)
Query expressions don't return null as far as I know. If there are no results you just get an IQueryable<T>
with no T
s inside.
You can use this instead to see if there's anything in the result set:
if (qry.Any())
presuming that should return a single value - if so, then:
var qry = (from x in db.DT_Control_ColourPalette_PageColors
where x.PageControlID == int.Parse(HF_CPID.Value)
select new
{
x.PageControlID,
}).FirstOrDefault();
if(qry != null)
{
// do stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With