check if a DataRow cell is null

Posted on 2005-04-13
Last Modified: 2010-08-05
i want to check if a datarow cell has anything in it.

if it is null - i will put a string.empty into it(i think this is best)

i am doing this so i can just populate a address object without worrying if it will break because the data cell is null.

my code which didnt work is:
//check address for nulls

if (dr["Postcode"] = null)
dr["Postcode"] = s;
Question by:MrKevorkian
    LVL 2

    Expert Comment

    by:Mohammad Aamir Qureshi
    plz give me more explanation
    LVL 1

    Author Comment

    i collect a dataset from the db.

    i want a way of checking if its datarows contents contain any data or if they are null

    if they are null then just assign a default empty string

    LVL 11

    Accepted Solution

    you should check against 'DBNull.Value' not 'null'
    or use DataRow.IsNull( "column name" )


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    How to Serailize Object to Array Json C# 7 36
    Obtaining values from inside a HTMLDocument 3 31
    report c# 9 56
    Handling arrays 14 28
    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now