473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to deal with integer that can be null in sql server?

I have integers in my database that can be null. I read them with
SqlDataReader and show them to Repeater. Since integer can not be null in
c#, I set null integer to -1. My project is 3-tier and it is very
complicated to check in data tier if it is null set -1, then in business
tier if it is -1 do not calculate with him and then in presentation tier "do
not show if it is -1". Is there any better solution for that?
Nov 18 '05 #1
5 1095
Hi Tomislav,

Maybe this link can help you:
http://nullabletypes.sourceforge.net

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"TomislaW" <to*********@ho tmail.com> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
I have integers in my database that can be null. I read them with
SqlDataReade r and show them to Repeater. Since integer can not be null in
c#, I set null integer to -1. My project is 3-tier and it is very
complicated to check in data tier if it is null set -1, then in business
tier if it is -1 do not calculate with him and then in presentation tier
"do not show if it is -1". Is there any better solution for that?

Nov 18 '05 #2
"TomislaW" <to*********@ho tmail.com> wrote:
I have integers in my database that can be null.
[...]
Since integer can not be null in c#, I set null integer to -1.


Use SqlInt32 (in System.Data.Sql Types) and SqlInt32.Null.

P.
Nov 18 '05 #3
Hi,

No really, no matter what you do you will have to check for a "null" it
does not matter if the "null" is -1 or null.

You would have to do the same thing even if a null value was available, you
would have to check by null before any operation.

nothing that a simple if can't solve. :)

Cheers,

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

"TomislaW" <to*********@ho tmail.com> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
I have integers in my database that can be null. I read them with
SqlDataReade r and show them to Repeater. Since integer can not be null in
c#, I set null integer to -1. My project is 3-tier and it is very
complicated to check in data tier if it is null set -1, then in business
tier if it is -1 do not calculate with him and then in presentation tier
"do not show if it is -1". Is there any better solution for that?

Nov 18 '05 #4
I decide to use SqlDataReader and asp:Repeater because of speed.

If I checking asp:Repeater on ItemDataBound I loose that speed, where to
check for nulls?

Is it better solution to build asp:Table in code behind?


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:e2******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

No really, no matter what you do you will have to check for a "null" it
does not matter if the "null" is -1 or null.

You would have to do the same thing even if a null value was available,
you would have to check by null before any operation.

nothing that a simple if can't solve. :)

Cheers,

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

"TomislaW" <to*********@ho tmail.com> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
I have integers in my database that can be null. I read them with
SqlDataRead er and show them to Repeater. Since integer can not be null in
c#, I set null integer to -1. My project is 3-tier and it is very
complicated to check in data tier if it is null set -1, then in business
tier if it is -1 do not calculate with him and then in presentation tier
"do not show if it is -1". Is there any better solution for that?


Nov 18 '05 #5
Hi,

I decide to use SqlDataReader and asp:Repeater because of speed.

This has nothing to do with the subject at hand the problem will exist no
matter what you use to show your data.
If I checking asp:Repeater on ItemDataBound I loose that speed, where to
check for nulls?
You could define a method that return the string you want to use to show
null, below is an example of such a construction from a datagrid

<ItemTemplate >
<asp:Label ID="lbl_inc_ide ntification" Text=<%# FormatID(
Container.DataI tem("inc_identi fication") )%> Runat="server"> </asp:Label>
</ItemTemplate>

in the code behind:

protected string FormatID( object o)
{
if ( ( int)o == -1 )
return "N/A";
return o.ToString();
}
Is it better solution to build asp:Table in code behind?
Absolutly not !
Cheers,

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


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:e2******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

No really, no matter what you do you will have to check for a "null" it
does not matter if the "null" is -1 or null.

You would have to do the same thing even if a null value was available,
you would have to check by null before any operation.

nothing that a simple if can't solve. :)

Cheers,

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

"TomislaW" <to*********@ho tmail.com> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
I have integers in my database that can be null. I read them with
SqlDataReade r and show them to Repeater. Since integer can not be null in
c#, I set null integer to -1. My project is 3-tier and it is very
complicate d to check in data tier if it is null set -1, then in business
tier if it is -1 do not calculate with him and then in presentation tier
"do not show if it is -1". Is there any better solution for that?



Nov 18 '05 #6

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

Similar topics

8
472
by: william | last post by:
Hi Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it (string, integer, boolean type field) Thank willia
5
1599
by: TomislaW | last post by:
I have integers in my database that can be null. I read them with SqlDataReader and show them to Repeater. Since integer can not be null in c#, I set null integer to -1. My project is 3-tier and it is very complicated to check in data tier if it is null set -1, then in business tier if it is -1 do not calculate with him and then in...
15
29240
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 containing the sort key value specified; otherwise a null value if the sort key value does not exist." By "null value", does it mean System.DBNull? (I...
5
6581
by: Woody Splawn | last post by:
I have some code that looks like this: Dim SSN, LName, FName, M As String mySqlConnection = New SqlConnection(myConnectionString) Dim sql_Command As New SqlCommand( _ "Select SSN, LName, FName, M from Students WHERE (SSN = " + " '" + ProposedValue + "')", _ mySqlConnection) Try mySqlConnection.Open()
5
3047
by: Øyvind Isaksen | last post by:
I have a page with an optional integer-field, and one asp:calendar control. I use a stored procedure to save the data in SQL Server. When all fields contains data, the code works great! But if the user dont fill in the optional "price-field" (integer value), or if the user dont choose a date in the asp:calendar control, I get the message...
1
7411
by: redpayne | last post by:
Okay, I finally got this program to run according to what the book had us build it as. Now prof wants case 2 and case 3 to prompt again for input, check input to see if it is the correct type, then display a "correct" message if is correct. So, If you choose 2 from the original pane, you would be prompted to enter an integer. The program would...
1
2312
by: =?Utf-8?B?RG9u?= | last post by:
Hello, I'm creating a web service that will allow people to enter their contact information into a SQL Server table. I get it to work when I enter all of the fields and press the invoke button, but if I leave one of the integer fields(ie StateID) empty if errors out. I tried to make the parameters optionally but it says thats not possible...
20
12396
by: chutsu | last post by:
I'm trying to compare between pointer and integer in an "IF" statement how do I make this work? if(patient.id != NULL){ } Thanks Chris
21
2889
by: no1zson | last post by:
I do not even know how to correctly ask this question. I have an item field in the code I am about to post. Simple intger meant to be an item number for a cd. The user enters this number. Over the last week I have played with Add buttons, Del buttons, Modify and everything else and it brought to light a problem I want to address today. I have...
17
1848
by: matevzb | last post by:
I've ran into some fishy code that, at first glance, is buggy, but it seems to work correctly and none of the compilers I've tried (five so far, on various systems) gives any warnings. The code: ============================ #include <stdio.h> void fcn (char *str)
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6610
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.