DataSet Insert Null Value to Row

Posted on 2011-04-27
Last Modified: 2012-05-11

I have a Dataset that I want to programitically add a record to.  I want to add a null value for some of the fields but get an "Invalid Arguement" error when I try.

This works:
myDataset.myTable.AddmyTableRow(myID, myDate, myInt);

This does not work:
myDataset.myTable.AddmyTableRow(myID, null, null);

This does not work:

myDataset.myTable.AddmyTableRow(myID, "", "");

Open in new window

Question by:doddwell
    LVL 7

    Accepted Solution

    It would look like AddmyTableRow is setup like this?

    public static void AddmyTableRow(this DataTable dt, int id, DateTime date, int i)

    Open in new window

    If you want to be able to send null values to those, then you need to make them Nullable objects.  Using the below, you could pass a DateTime and integer value that are delcared as nullable.

    public static void AddmyTableRow(this DataTable dt, int id, DateTime? date, int? i)

    Open in new window


    Author Closing Comment

    My Code actually looks like this:

    public myTableRow AddmyTableRow(int myID, System.DatetTme myDate, int myValue)

    So I changed it to
    public myTableRow AddmyTableRow(int myID, System.DatetTme? myDate, int? myValue)


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    731 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

    19 Experts available now in Live!

    Get 1:1 Help Now