doctor069
asked on
null values in Public Property
Hi -
I have a public property (see code below) that could possibly be null when I go to write it to a db via insert I get an error even though my db table allows it to be null. If there is a value it works fine.
I thing I have to check for null and return it as db.null but nothing I do seems to work...
Thanks in advance
I have a public property (see code below) that could possibly be null when I go to write it to a db via insert I get an error even though my db table allows it to be null. If there is a value it works fine.
I thing I have to check for null and return it as db.null but nothing I do seems to work...
Thanks in advance
Public Class Info
Private _TestId As String
Public Property TestId() As String
Get
Return _TestId
End Get
Set(ByVal value As String)
_TestId = value
End Set
End Property
End Class
'sql - i wont bore you with to many details here - it works if there is a value
myCommand.Parameters.AddWithValue("@TestId", p3.TestId)
'--------------------------------------------------------------------
'here is what it tried
myCommand.Parameters.AddWithValue("@TestId", isNull(p3.TestId))
Private Function isNull(ByVal Field As Object) As Object
If String.IsNullOrEmpty(Field.ToString) = True Then
Return DBNull.Value
MsgBox("nothing")
Else
Return Field
End If
End Function
--------------------------------------------------------------------
Private Function isNull(ByVal Field As Object) As Object
If Field Is Nothing Then
Return DBNull.Value
MsgBox("nothing")
Else
Return Field
End If
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did the trick. Thanks for your help
Open in new window