DataTable.Insert and null values.

Posted on 2007-10-21
Last Modified: 2013-11-26
Hey there guys,
I am trying to do a insert into the database used the insert property generated by my xsd in visual studio.

CustomerData.Insert(FName, LName, BillAddress, BillCity, BillState, BillZip, Phone, CompName, Email, null, null, null, null, null, 0);

As you can see i am trying to pass null values on some of the comulns. The database allows nulls in these fields, the columns in the TableAdapter in my xsd file allows nulls, the AllowDBNull property of these fields is set to true. yet i am still getting a error when trying to pass these nulls.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: FLD_COMMENTS
Source Error:

Line 7258:            }
Line 7259:            if ((FLD_COMMENTS == null)) {
Line 7260:                throw new System.ArgumentNullException("FLD_COMMENTS");
Line 7261:            }
Line 7262:            else {

Am i missing something here?

Question by:Nugs
    LVL 21

    Accepted Solution

    Try settting it as DBNUll.value instead of null
    LVL 22

    Assisted Solution

    A null in the DB and a null in C# are two different beasts. If you want to insert a null, set the value for that parameter to:


    LVL 2

    Author Comment

    MSDN does not say that:

    " The EmployeeID and OrderDate columns are both type Nullable because the corresponding columns in the Northwind database allow nulls. You can call the Insert function passing Nothing (null in C#) in the place of type-safe parameters instead of setting a separate property or using another bulky mechanism to indicate that the fields are null. "
    LVL 2

    Author Comment

    Something wierd was happening here, i do not thin the changes and updates to my XSD file were being saved but i was able to fix this and am able to pass null as a value into these fields

    CustomerData.Insert(FName, LName, BillAddress, BillCity, BillState, BillZip, Phone, CompName, Email, null, null, null, null, null, 0);

    thanks for the input guys


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    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…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 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

    15 Experts available now in Live!

    Get 1:1 Help Now