Solved

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

Posted on 2008-10-23
3
723 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 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 63

Expert Comment

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

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.
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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