Link to home
Start Free TrialLog in
Avatar of DinuA
DinuAFlag for United Kingdom of Great Britain and Northern Ireland

asked on

LINQ Query Exception: Conversion failed when converting the nvarchar...

OS: Windows Server 2003 SP2, MS SQL Server 2005 SP2, Visual Studio 2008 SP1
The following LINQ query

Dim db As New IRISmasterDataContext
Dim LocalCodeList = From localcode In db.LocalCodes _
 Where (localcode.localCode = strLocalCode & _
   localcode.companyCode = strCompanyCode & _
   localcode.BSELcode = strELCODE) _
Select localcode.LocalCode

throws the following exception:
Conversion failed when converting the nvarchar value 'ro100702010' to data type bit.

ro1 is the value of strCompanyCode and is taken from a textbox control on that page.  Of course other values have the same effect.
No idea where 00702010 comes from and why nvarchar.
The table columns  of the table LocalCode are declared as:
      [BSELcode] [char](8) NOT NULL,
      [companyCode] [char](3) NOT NULL,
      [localCode] [char](7) NOT NULL,

The equivalent SQL Query works fine.
Other LINQ queries in the same web site project and with the same DB are working as expected.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DinuA

ASKER

Thank you very much Fernando.
Dinu
Not a problem, glad I was able to help.  ;=)