Assign: Value cannot be null. (Parameter 'source') List Error

Hi,

I declared a list variable and then use linq query to filter the data table. but when ever the condition does not satisy it returns empty or null value and throws error. What is the workaround to avoid this condition?

Assign: Value cannot be null. (Parameter ‘source’)

@dutta.marina

Before doing select…use .Count and check the count >0 using if condition…if yes then assign if no then that means no value is returned

Cheers

Hi @dutta.marina ,

Use if condition and check if filtered data Row Count > 0, if yes then assign else you can clone the datatable to return empty values
e.g.
If(YourDT.AsEnumerable().Where(Function(row) row(“Col1”).ToString.Equals(“Value”)).Count>0,YourDT.AsEnumerable().Where(Function(row) row(“Col1”).ToString.Equals(“Value”)).CopytoDataTable,YourDT.Clone)

Thanks,
Rashmi

@Anil_G

If list is returning a valid object i can use above code , but here list itself null so i cannot chain the count function. Once it goes to else block ot throws same error

@dutta.marina

Use this expression to check if it’s null or empty.

str_latestfile_link IsNot Nothing AndAlso str_latestfile_link.Count >0

Thanks,
Ashok :slightly_smiling_face:

@dutta.marina

the count to be done on dt.Asenuemrable.where(blah blah).count>0 then assign to list inside the then block …on else block do nothing

I understand list is where you are tryign to collect the data

cheers

1 Like

@dutta.marina

if resolved can you close this thread

else happy to help

cheers

@Anil_G

Done

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.