Results 1 to 3 of 3

Thread: Handling nulls from database query

  1. #1

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Handling nulls from database query

    Hi

    In VB6 you would handle null columns as follows:
    VB Code:
    1. Dim lcStrValue as string
    2. Dim lcObjRcs as ADODB.Recordset
    3.  
    4. lcStrValue = "" &  lcObjRcs!Surname

    I am now using VB.NET and picking up values from a DataRow object and getting an exception about DBNull.

    How do I handle Null in the code below assuming the Surname column in the table is null.


    VB Code:
    1. Dim oDataRow As DataRow
    2.  
    3. For Each oDataRow in dtTable.Rows
    4.     strSurname = oDataRow.Item("Surname")
    5. Next

    Thanks
    Last edited by Mr.No; May 3rd, 2004 at 05:31 AM.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  2. #2

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    [RESOLVED]

    I found this article on MSDN
    Much ADO About Nothing
    I find the handling of nulls still cumbersome though. Ideally I would prefer amethod or property on the ADO.NET object like object.ValueIfNull. The caller could set a value in this property before making the query and then whenever a column would be null the datarow would return the value set in ValueIfNull.......
    Last edited by Mr.No; May 2nd, 2004 at 01:09 PM.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  3. #3
    New Member
    Join Date
    May 2004
    Location
    Dubai
    Posts
    5
    You may try to use ISDBNull() method to determine if the field is null

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