473,398 Members | 2,113 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,398 software developers and data experts.

passing method parameters

I have a method which takes two parameters.. and they both come from database.

I get error message when one of the parameter from the database contain null
value.

What do i need to check to prevent getting this error? how do i check for
null value?? how can i replace the null value with (0) zero to stop this
error?

Many thanks

Eerror message: Specified cast is not valid.

int DBBrandID =(int)((DbDataRecord)e.Item.DataItem)["BrandID"];
int DBModelID =(int)((DbDataRecord)e.Item.DataItem)["ModelID"];

lblMakeModel.Text = cs.getBrandModel(DBBrandID,DBModelID);
Jul 21 '05 #1
1 1184
huzz <hu**@discussions.microsoft.com> wrote:
I have a method which takes two parameters.. and they both come from database.

I get error message when one of the parameter from the database contain null
value.

What do i need to check to prevent getting this error? how do i check for
null value?? how can i replace the null value with (0) zero to stop this
error?

Many thanks

Eerror message: Specified cast is not valid.

int DBBrandID =(int)((DbDataRecord)e.Item.DataItem)["BrandID"];
int DBModelID =(int)((DbDataRecord)e.Item.DataItem)["ModelID"];

lblMakeModel.Text = cs.getBrandModel(DBBrandID,DBModelID);


You can use DbDataRecord.IsDBNull to check for nullity. You might want
to have a helper method to return 0, eg:

int GetInt (DbDataRecord record, string columnName)
{
if (record.IsDBNull (columnName))
{
return 0;
}
else
{
return (int)record[columnName];
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
8
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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 project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.