-
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!
-
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
-
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.
-
If it's a varchar or nvarchar field, then the default value should just be ('') an empty string.
-
Yeah its an nvarchar field, so I can give that a go and see what happens. Cheers for the advice.