vb.net - Invalid Cast Exception Occurred -
i getting following error:
invalid cast exception occurred unable cast object of type 'system.data.linq.dataquery`1[windowsapplication1.designspec]' type 'windowsapplication1.designspec'
on following test code:
dim prodsku string = "11037" dim designspec designspec = row in dblocal.designspecs row.name = prodsku select row
i have searched high , low , have tried numerous options, not right option. in helping me use right syntax appreciated.
kind regards , thank in advance help!
ps: know sounds kind of cheesy, first post (hopefully i've posted adequately). have followed many threads have been incredibly helpful unable give vote because don't have reputation points -- truly! if enough question maybe vote give me enough reputation points can return favor of else's assistance. again!
the linq query return collection (of designspec
's), whereas trying assign single instance.
you'll need apply filter collection extracts single instance - e.g. single()
, singleordefault()
, first()
, firstordefault()
, etc depending on makes sense based on expected output of query.
keep in mind using single
variants result in exception if query happens return more 1 instance, whereas first
variants cope ok return first instance found.
Comments
Post a Comment