dealing with null value.

Posted on 2007-10-14
Last Modified: 2013-11-26
Does have a direct function that deals with nulls, When i am loading values from a database to a form, when one field is null, i get the error massage can't convert dbnull to string, I dont want to do test "if if not isnull("field") then form control = field value". for example access had a function (NZ) that could automatically convert nulls to empty strings or 0.

Question by:Anthony Matovu
    LVL 46

    Accepted Solution

    Hi MatovuAnthony,

    Not as far as I know. But you can force a string most of the time like this....

        FormControl.Text = dr("Field").ToString


    LVL 8

    Expert Comment

    You may always compare the value of a field with DbNull.Value:
    if dr("Field") = DBNull.Value then
       do something
    end if

    sorry for the syntax, I'm not a VB guy. DBNull.Value is defined in .NET.
    LVL 46

    Expert Comment

    by:Wayne Taylor (webtubbs)
    Copied from Anthony's question....

    "I dont want to do test "if if not isnull("field") then form control = field value""

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 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

    21 Experts available now in Live!

    Get 1:1 Help Now