Solved

How to pass null values  to test condition in where clause using LINQ

Posted on 2009-04-03
3
401 Views
Last Modified: 2013-11-11
my queries are

1) select * from tablename where col == null

2) select * from tablename where col  != null

i need this queries in LINQ.
0
Comment
Question by:ravindra333
[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
3 Comments
 
LVL 21

Accepted Solution

by:
naspinski earned 250 total points
ID: 24059987

var results1 = from p in YourDataContext.tablename where p.col == null select p;
 
var results2 = from p in YourDataContext.tablename where p.col != null select p;

Open in new window

0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 24061162
Hi ravindra333;

You can also use this form in Linq, The database must be a Microsoft SQL server in both solution post :

            var result1 = DataContext.TableName.Where(c => c.col  == null);
            var result2 = DataContext.TableName.Where(c => c.col  != null);

Where the c in the Where clause can be any name of your choosing.

Fernando
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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