For a C# 2010 application, I would like to be able to check for the value
returned by the linq to sql query listed below as being null.
Is there any way to check for
strOrgName == null?
string strOrgName = (from o in rData.Orgs
join pl in rData.Custs on o.OrgID equals pl.OrgID
where pl.orgnum == strContract
select o.OrgName).FirstOrDefault();
The code I have written so far only allows if I check for
strOrgName != null.
I am using the code above to use as an example of how I would like to be able
check for the value returned being a null.
Thus can you tell me how to solve my isuse?
Loading
VulpesPosted Sep 29, 2012, 6:17 PM
Shivanand ArurPosted Sep 29, 2012, 11:43 PM
if(strOrgName == null)
{
// Your Code here
}
or
if(String.IsNullOrEmpty(strOrgName))
{
//Your Code here.
}
dcPosted Sep 29, 2012, 5:20 PM
var strOrgName = (from o in rData.Orgs
join pl in rData.Custs on o.OrgID equals pl.OrgID
where pl.orgnum == strContract
select o.OrgName).FirstOrDefault();
How can I check for a null value in a 'var' declared field? I would like to say if
if strOrgName == null and not get a compile error?
Should I convert the var value to a string or int? How would you procede?
Shivanand ArurPosted Sep 29, 2012, 3:19 PM
if(!String.IsNullOrEmpty( strOrgName))
{
// Add your Logic 1
}
else
{
// Add your Logic 2
}
I hope this is what you wanted.... If not, then please post your question again... Thank you.