Results 1 to 5 of 5

Thread: Dbnull

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    London
    Posts
    107

    Dbnull

    Hi,

    I am trying to return a URL for a picture based on the file path (which is just an nvarchar value from my DB). This works fine when there are no nulls however in reality when the system is operational there will be nulls so I need it to be able to cope with this. I thought this should be an easy fix but none of the solutions I've seen to similar problems on this forum work! The line of code I have is:

    Private Sub Page_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DataBinding
    Dim dr As DataRow
    dr = Me.Dsplayers.View_Player_Stats.DefaultView(Position).Row

    Me.TextBox1.Text = DataBinder.Eval(dr, "Player_ID")
    Me.TextBox3.Text = DataBinder.Eval(dr, "Player_Name")
    Me.Image3.ImageUrl = DataBinder.Eval(dr, "Photo_Path")

    If anyone has any ideas please let me know!

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    1) Databases should never contain NULL's in a field. You should always set a default value for the field.

    2) Check for DBNull...More info from MSDN
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    London
    Posts
    107
    As a general rule maybe, but I don't have a photo for everyone, so if I put in a default URL surely this would bring up an error, unless I suppose it pointed to a blank default picture. Incidentally what I've done for the moment is amended the query itself so that each field is part of an isnull statement ie. isnull(photo_path,'') as Photo_Path which seems to return what I was hoping.

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    If it's a varchar or nvarchar field, then the default value should just be ('') an empty string.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    London
    Posts
    107
    Yeah its an nvarchar field, so I can give that a go and see what happens. Cheers for the advice.

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