Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

765 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