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

  • SEARCH
  • Home
  • 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 3965444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:27:53+00:00 2026-05-20T03:27:53+00:00

I have run into this problem a few times and have never come up

  • 0

I have run into this problem a few times and have never come up with a good answer. I figure others must have dealt with this already.

I have a datareader returned from the database and I want to use the values therein however values may or may not contain NULL. I would like to have a helper function that takes in the value from the datareader and returns the value if it is not NULL and blank space if it is NULL.

The problem I have is that the data-type of the variable I am testing is variable. It can be a String, and Integer or a DateTime. Can anyone suggest a simple way to test the value and then return the original value (as same data-type if possible) or something else if it is NULL?

I am using VB.NET at the moment but I would also like to know how to do this in C#. Thank you.

  • 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-20T03:27:53+00:00Added an answer on May 20, 2026 at 3:27 am

    This should work for most things I believe (I’ve not tested it mind):

     public T ParseValue<T>(System.Data.SqlClient.SqlDataReader reader, string column)
     {
         T result = default(T);
    
         if (!reader.IsDBNull(reader.GetOrdinal(column)))
             result = (T)reader.GetValue(reader.GetOrdinal(column));
    
         return result;
     }
    

    And will return you the default value for that type if it is null

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've run into this issue quite a few times and never liked the solution
Has anyone run into this problem... In my layout.phtml I have: <head> <?= $this->headTitle('Control
I've run into the following a few times with initializer lists and I've never
This is an odd thing I've just run into. I have a web application
I have run into a common, yet difficult problem. I do not use Photoshop
I have run into a bit of a tricky problem in some C++ code,
I have run into a few cases where i have been asked to deploy
it seems I have run into a problem with Internet Explorer 7. I have
I'm using SWFUpload to handle file uploads and have run into a problem where
I have run into a datetime related problem, my program needs to varify whether

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.