Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

need C++ syntax, data table tertiary "if null use default value"

Posted on 2013-11-20
1
Medium Priority
?
326 Views
Last Modified: 2013-11-20
I need the syntax for changing the last line to a tertiary "if" that checks if the data is null, uses a default value if the data is null (say 0), otherwise uses the data value.
using System.Data;
...
        public FacilityData(DataRow DRow)
        {
            SiteID = (int)DRow["SiteID"];

Open in new window

0
Comment
Question by:deleyd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
Beartlaoi earned 400 total points
ID: 39663227
Ternary is the type of expression you are looking for.
<boolean> ? <true expression> : <false expression>
Use the IsNull member of DataRow to see if the underlying data is DBNull
SiteID = DRow.IsNull("SiteID") ? (int)0 : (int)DRow["SiteID"]; 

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question