ss2030

Hi there, I am new at this and have been experimenting with linq. I received the following error even though the linq query always brings up a string.

"Runtime errors might occur when converting 'system.linq.IQueryable(of String)' to 'String' "

I am using the following code.


Dim getClients As New manageClients
Dim clientList As New List(Of displayClientList)

Dim filterValue = From code In db.codes _
Where code.description = cbxFilter.Text _
Select code.code.Distinct

clientList = getClients.loadClients(filterValue, txtClientSearch.Text)


I am getting the error on the function "loadCients" and specifically "FilterValue" as this value is set as a string in the function parameter.

How do I cast the linq result as a string and fix the cast error

Hope someone can help... simon



Re: LINQ Project General Runtime errors might occur when converting 'system.linq.IQueryable(of String)' to 'String'

Chunsheng Tang - MSFT

Hi, simon

The query(i.e.filterValue) is of the type of IQueryable(of string), and you cannot cast it as a string. You may change the argument type of the loadClient method to IQueryable(of string), or you can pass it as an Object and cast it back to IQueryable(of string) within the loadClients method.

Best Regards

Chunsheng Tang






Re: LINQ Project General Runtime errors might occur when converting 'system.linq.IQueryable(of String)' to 'String'

ss2030

Thanks Chunsheng... that has helped alot.