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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:02:03+00:00 2026-06-09T01:02:03+00:00

if (statement) base.Database.AddInParameter(command, ColumnX, DbType.String, StackOverflow); else base.Database.AddInParameter(command, ColumnX, DbType.String, DBNull.Value); I want to

  • 0
if (statement)
     base.Database.AddInParameter(command, "ColumnX", DbType.String, "StackOverflow");
 else
     base.Database.AddInParameter(command, "ColumnX", DbType.String, DBNull.Value);

I want to do this statement in one line by using

? "true" : "false" 

For example:

if(statement) ? base.Database.AddInParameter(command, "ColumnX", DbType.String, "StackOverflow") : base.Database.AddInParameter(command, "ColumnX", DbType.String, DBNull.Value);

but this is not true. Visual studio says that unexpected token for ” : “

any idea? thanks

  • 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-09T01:02:06+00:00Added an answer on June 9, 2026 at 1:02 am

    First of all, the if before (statement) is not needed for the conditional operator.

    Secondly, you can’t use it as both sides of the conditional need to be the same type or types where one is implicitly convertible to the other – string and DBNull.Value are not such types.

    You can use it if you cast either the string or DBNull.Value to object:

    base.Database.AddInParameter(
                                 command, 
                                 "ColumnX", 
                                 DbType.String, 
                                 statement ? "StackOverflow" : (object)DBNull.Value);
    

    However, if I had to read this on one line, I would find it less readable than the original version you posted – there is no value in having this logic in one line, in particular if it reduces readability and makes the code less easy to understand.

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

Sidebar

Related Questions

I would like to write an if statement that will do something base on
Statement st=conn.createStatement(); String sql=SELECT a.ID,a.A_TEXT,a.B_TEXT,a.C,a.D_TO_E,a.F_TEXT,a.G,a.INTIME,b.EXIT_TIME FROM tm_A a LEFT JOIN tm_B b ON a.ID=b.ID
Statement: Static member variables can be ONLY changed by static methods. Is this statement
This statement is returning error 00920- invalid relational operator. I am sure it is
Problem statement We have one employer that wants to interview N people, and therefore
This example is from the Django documentation . Given the (Django) database model: class
I have a legacy data base and a relation one-to-one between two tables. The
In ajax.py, I have this import statement: import components.db_init as db In components/db_init.py, I
I want to create a new AnswerStat object and save it in the database.
I want to preface this question by stating that I am fairly new to

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.