how to check null value in database sql query c#
  • Hello

    I want to perform following query

    Select * from tblName Where id="22" and date=NULL

    I tried following queries in c# but no result from database in shown

    select * from tbl where id='"+txtBox.Text+" AND date=''';
    select * from tbl where id='"+txtBox.Text+" AND date='';

    select * from tbl where id='"+txtBox.Text+" AND date=NULL;
    select * from tbl where id='"+txtBox.Text+" AND date='Null';

    Please tell me how can i apply Where clause to a null  column in DB.

    Thanks
  • 1 Comment sorted by
  • your query should be 

    select * from tblName where id='22' and Date is Null

    because you should not compare NULL with = 

    so in your c sharp code your query will be like this

    "select * from tblName where id='"+txtBox.Text+"' and Date is NULL"

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Top Posters Weekly

Optimum Creative