473,385 Members | 1,445 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,385 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 1182
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.