Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now