?
Solved

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

Posted on 2008-10-23
3
Medium Priority
?
727 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 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 63

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

764 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