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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:14:59+00:00 2026-06-10T03:14:59+00:00

Alright, maybe I am going around this wrong. We shall see. So there is

  • 0

Alright, maybe I am going around this wrong. We shall see.

So there is some data I am checking. This data is going to be type Int32. More or less, if the item wasn’t one of my flags, I wanted to set it as DBNull.value, I believe.

The thing I am trying to determine is that the column is nullable, so if I don’t enter anything into it, it shall be set to null.

Here is my program logic:

int content = 5;  //set for sake of program;
int test;
if( content == 5){
  test = content;
}else{
  //i want test to be labeled as DBNULL.
  //didnt know if i could redefine here to be like:
  //      free(test); DBNull test = new DBNull;
}
//my companys db command
CommandFactory cmd = new CommandFactory();
cmd.commandText = "insert into TABLE ( value ) values ( @a )";
cmd.addInputParameters("@a", test, DBType.Int32);
...

In this case, how would is et it to dbnull? be like:

if(test != -1){
    cmd.addInputParameters("@a", test, DBType.Int32);
}
//no param would be entered for @a, maybe forcing it to be null?

In the definition of the table, value is nullable, so you wouldn’t need to worry about that.

While the correct answer is posted, it is not the one I ended up using as my coworkers didn’t want me to do “magic” with ??, so they had me do:

int? temp;
if(temp.HasValue){
    cmd.addInputParameters("@a", temp, DBType.Int32);
}else{
    cmd.addInputParameters("@a", DBNull.Value, DBType.Int32);
}
  • 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-06-10T03:15:01+00:00Added an answer on June 10, 2026 at 3:15 am

    How about:

    int? test = content
    ...
    cmd.addInputParameters("@a", (object)test ?? DbNull.Value, DBType.Int32);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright I created some custom classes for my project sourced from this tutorial ,
Alright so I have been looking around (on SO and Google) to see if
Allright, this might be a strange question and maybe I am heading the wrong
Alright, I am going to state up front that this question may be too
Alright, I have been breaking my head over this one for more than a
Alright, this maybe the simplest (or the stupidest) question, but I just got to
Alright, Im going about this, with what is probably a really complicated solution, but
Alright, this is driving me nuts because my regex is working on Rubular, but
Alright so I have no idea how to even begin doing this But basically

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.