Advertisement

02.07.2008 at 03:33PM PST, ID: 23146439
[x]
Attachment Details

Loading a Null value into an int variable

Asked by gjok in C# Programming Language, Programming for ASP.NET, .NET Framework 2.0

Tags: C#

I am loading values from a database record into a class. One of the class properties is an int, which corresponds to an int fiel in the database.
However, sometimes the DB value in null, which causes an exception when assigning the value to the class property.

I know I can set defaults on the database, but I am more curious to learn how to handle this kind of problem for future reference.
What is the standard proceure for dealing with this problem?

ThanksStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
private int? _sslPort;
 
public int? SSLPort
{
  get { return _sslPort; }
  set { _sslPort = value; }
}
 
Domain myDomain = new Domain();
myDomain.SSLPort = int.Parse(dr["SSLPort"].ToString()) ?? 0; // Error
myDomain.SSLPort = Convert.ToInt32(dr["SSLPort"]) ?? 0; // Error
[+][-]02.07.2008 at 03:37PM PST, ID: 20846543

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 04:31PM PST, ID: 20846843

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 04:33PM PST, ID: 20846853

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 04:51PM PST, ID: 20846947

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 04:53PM PST, ID: 20846955

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 05:02PM PST, ID: 20846977

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 05:11PM PST, ID: 20847013

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 05:14PM PST, ID: 20847035

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 05:24PM PST, ID: 20847084

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 05:31PM PST, ID: 20847123

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 05:41PM PST, ID: 20847179

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.08.2008 at 03:27AM PST, ID: 20849214

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.08.2008 at 06:10AM PST, ID: 20850148

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, Programming for ASP.NET, .NET Framework 2.0
Tags: C#
Sign Up Now!
Solution Provided By: Yiogi
Participating Experts: 4
Solution Grade: A
 
 
[+][-]02.08.2008 at 06:19AM PST, ID: 20850241

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628