|
-
Mar 27th, 2007, 09:41 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Nullable Object Properties ASP.Net 1.1
Hi there
im trying to find an resolution to a problem im having.
I have an object which has several integer/date properties
I use a datareader to load data from the database into these objects.
The issue is when i have null values for the integer/date fields.
i use the following function to loaddata into the properties:
s Code:
myobject.mynumber = getNullInt32(l_dr, 0)
Private Function getNullInt32(ByVal p_reader As SqlDataReader, ByVal p_index As Integer) As Integer
Dim l_retInteger As Integer = Nothing
If Not p_reader.IsDBNull(p_index) Then
l_retInteger = p_reader.GetInt32(p_index)
End If
Return l_retInteger
End Function
so when my column has a null value in the table the function returns 0 which
sets the property myobject.mynumber to 0, when the value it not 0.
So i cannot distinguish the difference between a table field having 0 in it or nothing in it.
Is there any way to do the following from ASP 2.0 in ASP 1.1
s Code:
Public Property mynumber as Nullable(Of Integer)
this is very frustrating.
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Mar 27th, 2007, 10:31 AM
#2
Re: Nullable Object Properties ASP.Net 1.1
I had a similar issue quite a while ago and we got around it by using SQLTypes you can read null's straight into these from the database.
e.g.
Code:
using System.Data.SqlTypes;
private SqlInt32 _score;
Code:
public SqlInt32 Score
{
get { return _score; }
set { _score = value; }
}
Code:
_score = dr.GetSqlInt32(dr.GetOrdinal("Score"));
This is how we got around the problem at the time although there well be a better way.
-
Mar 27th, 2007, 01:53 PM
#3
Re: Nullable Object Properties ASP.Net 1.1
In ASP.NET 1.1, you can't. You can use FC's method, or just use DBNull.Value to represent a null value.
-
Apr 1st, 2007, 12:58 PM
#4
Thread Starter
Fanatic Member
Re: Nullable Object Properties ASP.Net 1.1
thanks for the info guys.... looking forward to 2005, whenever we upgrade (sigh)
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Apr 2nd, 2007, 09:03 AM
#5
Re: [RESOLVED] Nullable Object Properties ASP.Net 1.1
If your company is anything like mine, you'll be upgrading when VS 2009 comes out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|