Solved

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

Posted on 2008-10-23
3
717 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
ID: 22789106
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
ID: 22789531
Thank you very much Fernando.
Dinu
0
 
LVL 62

Expert Comment

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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