It looks like you are using LINQ to SQL. This error comes directly from the SQL Server executing the query (and not from your code). I assume that you have a SOME string with a value that is not a valid numeric value.
I would execute the following query in SSMS, and I think you will find that it fails with an error
Error Converting data type varchar to float select convert(float, value) from leaddata
EDIT:
If you want to add some fault tolerance, as John suggested, you can map the IsNumeric function and do the following:
In your DBML (link How to find out if a field is numeric in Linq To SQL )
<Function Name="ISNUMERIC" IsComposable="true"> <Parameter Name="Expression" Parameter="Expression" Type="System.String" DbType="NVarChar(4000)" /> <Return Type="System.Boolean" DbType="BIT NOT NULL"/> </Function>
In your code:
double target = Convert.ToDouble(value); Items = Items.Where(p => p.LeadDatas.Where(i => myDataContext.IsNumeric(i)).Any(q => q.LeadField.Name == descriptor.Name && Convert.ToDouble(q.Value) == target));
source share