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 7680757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:11:20+00:00 2026-05-31T18:11:20+00:00

I have written a relatively big insert statement, and some of the fields are

  • 0

I have written a relatively big insert statement, and some of the fields are null.

I cannot convert from db null to other types and I don’t really want to check Convert.IsDBNull for every single item

What should I do?

 System.Data.OleDb.OleDbCommand iCommand = new System.Data.OleDb.OleDbCommand("Insert into ProductCode values('" +
                    greader["CODE"].ToString() +
                    "','" + Convert.ToChar(greader["DISC_CODE01"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE02"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE03"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE04"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE05"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE06"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE07"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE08"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE09"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE10"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE11"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE12"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE13"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE14"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE15"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE16"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE17"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE18"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE19"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE20"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE21"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE22"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE23"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE24"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE25"]) +
                    "','" + Convert.ToChar(greader["DISC_CODE26"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT01"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT02"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT03"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT04"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT05"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT06"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT07"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT08"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT09"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT10"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT11"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT12"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT13"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT14"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT15"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT16"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT17"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT18"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT19"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT20"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT21"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT22"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT23"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT24"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT25"]) +
                    "','" + Convert.ToDouble(greader["DISC_PCT26"]) +
                    "')", iConnect);
  • 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-31T18:11:21+00:00Added an answer on May 31, 2026 at 6:11 pm

    Without analysing why you’re using the above method, I’d simply write my own method to do this. Simply write your own Convert.ToChar and Convert.ToDouble, something like this:

    public class MyConvert
    {
        public static char ToChar(object value, char defaultValue)
        {
            return Convert.IsDBNull(value) ? defaultValue : Convert.ToChar(value);
        }
    }
    

    So rather than having a Convert.ToChar(greader["DISC_CODE01"]) you would use MyConvert.ToChar(greader["DISC_CODE01"], ''). Do the same for double as well.

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

Sidebar

Related Questions

I have written an assembly I don't want other people to be able to
I have written an AIR Application that downloads videos and documents from a server.
I have written some code in my VB.NET application to send an HTML e-mail
I am still relatively new to unit testing. I have written a class in
I am relatively new to Perl.I have been trying to insert data to database
I have written some code which produces simple animations based on cycling through a
I have written a relatively simple Java App Engine application which I would like
I have written a Scheme evaluator in Java that does some parallelisation tricks. It's
I have a relatively large application written in Python and using PyQT as a
I have a JTable displaying rows from an SQL database. The table is relatively

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.