Results 1 to 5 of 5

Thread: [RESOLVED] Nullable Object Properties ASP.Net 1.1

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Resolved [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:
    1. myobject.mynumber = getNullInt32(l_dr, 0)
    2.  
    3.  
    4. Private Function getNullInt32(ByVal p_reader As SqlDataReader, ByVal p_index As Integer) As Integer
    5.         Dim l_retInteger As Integer = Nothing
    6.         If Not p_reader.IsDBNull(p_index) Then
    7.             l_retInteger = p_reader.GetInt32(p_index)
    8.         End If
    9.         Return l_retInteger
    10.     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:
    1. 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

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    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.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  4. #4

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    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

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width