[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. :mad:
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.
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.
Re: Nullable Object Properties ASP.Net 1.1
thanks for the info guys.... looking forward to 2005, whenever we upgrade (sigh)
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.