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

transition a null value in database into a code

Hi,

Imagine that we have a database and one table. Stored procedure returns 3
columns of table: ID, name, value.
Name and value can be a null in database. How to map or represent such
values in .net code? When I map a null value to a string or double variable I
get an error.

I have heard that one of solutions can be converting and representing
db.null as a minimum value of used type. Is it a good technic? And what in
situaltion when I need all the values variable can represent from minimum to
maximum?

Thanks.
Przemo
Nov 17 '05 #1
3 3545
Przemo,

If you are using .NET 2.0, you can use the nullable type.

When you are dealing with your data set though, you can use the return
value from the Value property on DBNull to indicate null in a database.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Przemo" <Pr****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi,

Imagine that we have a database and one table. Stored procedure returns 3
columns of table: ID, name, value.
Name and value can be a null in database. How to map or represent such
values in .net code? When I map a null value to a string or double
variable I
get an error.

I have heard that one of solutions can be converting and representing
db.null as a minimum value of used type. Is it a good technic? And what in
situaltion when I need all the values variable can represent from minimum
to
maximum?

Thanks.
Przemo

Nov 17 '05 #2
Hi,

before assigning the value readed from the DB you can check for
DBNull.Value , if true then you have to decide what to do, possibles options
include:

1- In case of values types assign a especific value, like Int32.MinValue,
Int32.MaxValue, etc
1.a - In references types, you can always assign null and later check for
it, or you can use a "default" instance

2- In case that all the values of a type are possible (like bool) you have
to define a wrapper, with two members, the value and a flag that indicate if
the value exist or not

3- Upgrade to 2.0 that include a nullable type
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Przemo" <Pr****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi,

Imagine that we have a database and one table. Stored procedure returns 3
columns of table: ID, name, value.
Name and value can be a null in database. How to map or represent such
values in .net code? When I map a null value to a string or double
variable I
get an error.

I have heard that one of solutions can be converting and representing
db.null as a minimum value of used type. Is it a good technic? And what in
situaltion when I need all the values variable can represent from minimum
to
maximum?

Thanks.
Przemo

Nov 17 '05 #3
Another option to consider is having your database do some of the work
for you. You may have a SQL command like NVL, that will return the
value for the column if it isn't null or some default value if it is
null.

Example:
SELECT fname, NVL (addr, 'Address unknown') AS address
FROM employees

(This is the Informix NVL syntax)

Nov 17 '05 #4

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

Similar topics

3
by: Richard A. DeVenezia | last post by:
I hope this is the end of my present 'discovery' phase. I've learned alot about JavaScript in a short time and my head hurts. The following is what came out of all my questions and all the...
4
by: James Fisher | last post by:
How are people handling NULL values for value types. Descriptions of problem Say you have a typical method with the signature: public int InsertPerson(string firstName, string lastName, int...
7
by: Dan | last post by:
I'm fairly new to C# and I am having some problems understanding int variables and null values. I have created a class that populates the values of it's fields from a DataReader in it's...
1
by: Don Rixtown | last post by:
I ran into a very strange error tonight. I was working with web services and typed datasets. The web server I was using happens to be on the other end of a virtual network (Hamachi). Everything...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
0
by: krishna81m | last post by:
Could some one please explain why the session is not being maintained when I am doing a forward in a servlet after setting a cookie. I am even unable to set session attributes or parameters and...
3
by: frostbb | last post by:
Greetings, We're starting to transition our legacy C# apps from earlier versions to VS2008 versions. Many of our apps allow the user to select a row from a DataGrid into a 'Data Edit' area...
3
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.