Solved

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

Posted on 2013-11-20
1
321 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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 39
C++ to C# code conversion issue 4 120
Dynamically allocate memory 9 70
Can Live bindings change TGrid Cell Colour ? 1 33
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

733 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