Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 505873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:38:35+00:00 2026-05-13T06:38:35+00:00

I’m working with an existing object framework that uses special values to represent NULL

  • 0

I’m working with an existing object framework that uses special values to represent NULL for primitives int, DateTime, long. Data containing these values are added to a DataTable and displayed in third-party controls such as XtraGrid.

All is fine, except when aggregates are applied to the data. In this case, obviously the special values are processed instead of the NULL entries.

So I think the best solution is to map the values to/from DBNull when putting into the DataRow. I thought about subclassing the DataTable and DataRow, but the base classes don’t allow overriding of the accessors.

I could add extra Get/Set functions to the subclasses but this relies on remembering to use them. I could add static helper functions instead of subclassing, but this has the same problem.

Is there a more elegant solution?

Update
It’s the grid itself that is doing the aggregation, as it has flexible controls to let the user define summaries at run-time. So I think the only real solution is to map to/from DBNull somehow, just looking for an elegant way of doing this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:38:36+00:00Added an answer on May 13, 2026 at 6:38 am

    You may create an extension method to help you fill the datatable and convert values to dbnull:

    public static class DataExtensions
    {
        public static DataRow AddRow(this DataRowCollection rowCollection, params object[] values)
        {
            object[] newValues = new object[values.Length];
    
            for(int i=0;i<values.Length;i++)
            {
                object value = values[i];
                if (value != null)
                {                    
                    Type t = value.GetType();
                    //check for min value only for value types...
                    if (t.IsValueType)
                    {
                        //maybe you can do some caching for that...
                        FieldInfo info = t.GetField("MinValue",
                            System.Reflection.BindingFlags.Static
                            | System.Reflection.BindingFlags.Public
                            );
                        if (info != null)
                        {
                            object o = info.GetValue(null);
                            if (value.Equals(o))  //very important == will return false
                            {
                                value = DBNull.Value;
                            }
                        }
                    }
                }
                newValues[i] = value;               
            }
    
            return rowCollection.Add(newValues);
        }
    }
    

    And then you will be able to write something like:

    t.Rows.AddRow(a,b,c,d,e);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 290k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can just include an extra column in each select… May 13, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer Try the following: digraph simpsons { subgraph Generation0 { rank… May 13, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer Take a look at CompleteFTP, which supports SFTP on Windows,… May 13, 2026 at 5:53 pm

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.