Solved

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

Posted on 2008-10-23
3
713 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:DinuA
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
Hi DinuA;

Did you mean this to be the query using the "And" operator and not the "&"?

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

Fernando

0
 

Author Comment

by:DinuA
Comment Utility
Thank you very much Fernando.
Dinu
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now