473,396 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Value can not be Null

Jac
Hey,

public class Sessie : SessieBase
{
public Contract Contract;

public Sessie()
{
Contract Contract = new Contract ();
this.Contract = Contract;
}
}

public class ContractBase
{
private string mContractNr;
public string ContractNr
{
get
{
return mContractNr;
}
set
{
mContractNr = value;
}
}

private Status mStatusCd;
public Status StatusCd
{
get
{
return mStatusCd;
}
set
{
mStatusCd = value;
}
}

public ContractBase()
{
this.StatusCd = new Status();
}
}

public class Contract: ContractBase
{
}
Somewhere in the code I want to that :

this.TxtContractnr.Text = (this.Sessie.Contract.ContractNr == null ? "" :
this.Sessie.Contract.ContractNr.ToString());

this.TxtStatus.Text = (this.Sessie.Contract.StatusCd.Desc == null ? "" :
this.Sessie.Contract.StatusCd.Desc.ToString());
I receive : A first chance exception of type 'System.ArgumentNullException'
occurred in system.windows.forms.dll

Additional information: Value cannot be null.

But that is just the test I will do.
In first case if my string is null show “”, but there is a problem with
ContractNr. How can I test such a thing?
In the second the object is created but there is no value in it. I will test
that to see which value I want to show on screen. Ok StatusCd is null, so
there is no property Desc. I understand, but the I have to test always if
StatusCd is not null and then I have to test the Desc-property.
I think it is too much, I don’t see a good and short solution for that.
Try and Catch? But then the program will be full of try and catches.

Can some one point me out.

Thanks in advance

jac



Nov 17 '05 #1
2 4870
Change your private member to

private string mContractNr = "";

"Jac" wrote:
Hey,

public class Sessie : SessieBase
{
public Contract Contract;

public Sessie()
{
Contract Contract = new Contract ();
this.Contract = Contract;
}
}

public class ContractBase
{
private string mContractNr;
public string ContractNr
{
get
{
return mContractNr;
}
set
{
mContractNr = value;
}
}

private Status mStatusCd;
public Status StatusCd
{
get
{
return mStatusCd;
}
set
{
mStatusCd = value;
}
}

public ContractBase()
{
this.StatusCd = new Status();
}
}

public class Contract: ContractBase
{
}
Somewhere in the code I want to that :

this.TxtContractnr.Text = (this.Sessie.Contract.ContractNr == null ? "" :
this.Sessie.Contract.ContractNr.ToString());

this.TxtStatus.Text = (this.Sessie.Contract.StatusCd.Desc == null ? "" :
this.Sessie.Contract.StatusCd.Desc.ToString());
I receive : A first chance exception of type 'System.ArgumentNullException'
occurred in system.windows.forms.dll

Additional information: Value cannot be null.

But that is just the test I will do.
In first case if my string is null show “”, but there is a problem with
ContractNr. How can I test such a thing?
In the second the object is created but there is no value in it. I will test
that to see which value I want to show on screen. Ok StatusCd is null, so
there is no property Desc. I understand, but the I have to test always if
StatusCd is not null and then I have to test the Desc-property.
I think it is too much, I don’t see a good and short solution for that.
Try and Catch? But then the program will be full of try and catches.

Can some one point me out.

Thanks in advance

jac


Nov 17 '05 #2
Hi Jac

you could try this
(this.Sessie.Contract.StatusCd == null || this.Sessie.Contract.StatusCd.Desc
== null)
this will yield true if StatusCd is null or StatusCd.Desc is null.

"Jac" <Ja*@discussions.microsoft.com> schrieb im Newsbeitrag
news:42**********************************@microsof t.com...
Hey,

public class Sessie : SessieBase
{
public Contract Contract;

public Sessie()
{
Contract Contract = new Contract ();
this.Contract = Contract;
}
}

public class ContractBase
{
private string mContractNr;
public string ContractNr
{
get
{
return mContractNr;
}
set
{
mContractNr = value;
}
}

private Status mStatusCd;
public Status StatusCd
{
get
{
return mStatusCd;
}
set
{
mStatusCd = value;
}
}

public ContractBase()
{
this.StatusCd = new Status();
}
}

public class Contract: ContractBase
{
}
Somewhere in the code I want to that :

this.TxtContractnr.Text = (this.Sessie.Contract.ContractNr == null ? "" :
this.Sessie.Contract.ContractNr.ToString());

this.TxtStatus.Text = (this.Sessie.Contract.StatusCd.Desc == null ? "" :
this.Sessie.Contract.StatusCd.Desc.ToString());
I receive : A first chance exception of type
'System.ArgumentNullException'
occurred in system.windows.forms.dll

Additional information: Value cannot be null.

But that is just the test I will do.
In first case if my string is null show "", but there is a problem with
ContractNr. How can I test such a thing?
In the second the object is created but there is no value in it. I will
test
that to see which value I want to show on screen. Ok StatusCd is null, so
there is no property Desc. I understand, but the I have to test always if
StatusCd is not null and then I have to test the Desc-property.
I think it is too much, I don't see a good and short solution for that.
Try and Catch? But then the program will be full of try and catches.

Can some one point me out.

Thanks in advance

jac


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Morgan | last post by:
In an SQL statement which concatenates several fields I get a null value returned if any one of the fields are null. Is this to be expected? For example : SELECT tblMember.memberAddress + '...
2
by: Joel | last post by:
Hi, I added a field to my company table (PBV_rstCompany.Fields("Installer")) the default value of the field is Null. I place this If statement and it doesn't work If...
10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
5
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
15
by: TC | last post by:
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which contains the "index of the row in the DataView...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
1
by: Phil Mc | last post by:
Trying to call a stored proc but some times don't want to have values inserted in some fields. Hi I am rewriting a VBS script which called a stored proc in a SQL server db. The proc takes a...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
7
by: tlyczko | last post by:
I have a char(11) for SSN, and I would like to default it to 123-45-6789 so I can avoid having nulls in this column, and so I can easily find the rows in which I need to have a 'correct' SSN...
26
by: Ping | last post by:
Hi, I'm wondering if it is useful to extend the count() method of a list to accept a callable object? What it does should be quite intuitive: count the number of items that the callable returns...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.