Skip to main content
2 of 2
deleted 20 characters in body
MattDavey
  • 1.2k
  • 8
  • 16

You could define an extension method like this (I'm not a VB programmer so please excuse the syntax errors):

<Extension()> 
Public Sub OrDBNull(ByVal val As Decimal)
    If val = 0
        return DBNull.Value
    End If

    return val ;
End Sub

So your command parameters would become:

sqlCommand.Parameters.Add(New SqlParameter("GroupID", SqlDbType.Decimal)).Value = groupObj.OrDBBull()
sqlCommand.Parameters.Add(New SqlParameter("SiteID", SqlDbType.Decimal)).Value = siteObj.OrDBNull()
MattDavey
  • 1.2k
  • 8
  • 16