Using Linq in VB.NET to verify result set is NULL -
i'm trying validate wether or not 2 matching columns exists using linq/vb.net
i believe assuming null result set being returned 'count' value should null, correct?
below code;
dim crewnumentered = crewnuminput.text dim crewleadernumentered = crewleadernuminput.text dim crewnumunique boolean = false using db new dbclassdatacontext dim count = (from in db.warrantypercents a.crewleadernum = crewleadernumentered , a.crewnum = crewnumentered select a.warrantypercentsid).tolist if count nothing crewnumunique = true else 'throw error end if end using
the end result want perform action (code not shown) if crewnumunique == true.
but when result set should null, code continuing fill 'something' count.
what can fix this?
edit: realized value of count isn't null instead returning string 'system.collections.generic.list`1[system.int32]'. have no clue going on.
the query return result set when no matching rows found.
the below sets crewnumunique true if there 1 result. if instead want set crewnumunique true when there no results, use 0 in place of 1.
dim result = in db.warrantypercents a.crewleadernum = crewleadernumentered , a.crewnum = crewnumentered dim count integer = result.count if count = 1 crewnumunique = true else 'throw error end if
Comments
Post a Comment