Dune said:
Public Sub UpdateUser(ByVal userId As Integer, ByVal
active as Boolean, ByVal Name as String, ...)
So, in my stored procedure itself, I will check for NULL
before updating.
This means that whoever calls the UpdateUser method has a
choice of whether they want to update the Active field or
not. If they don't want to update it, they can just pass
in Nothing to the method. However, because I cannot
compare Nothing to a Boolean, the code above will not work.
As Booleans can not store Nothing, you could write an overloaded version:
Public Sub UpdateUser(ByVal userId As Integer, ByVal Name as String, ...)
If you've got a lot of arguments, you might consider other approaches, too.
For example, you could write one procedure and a "Flags" argument that
determines which fields are relevant:
<flags()> _
Enum FieldsToUpdate
Active
Name
'...
end enum
Public Sub UpdateUser(ByVal userId As Integer, byval Flags as
FieldsToUpdate, ByVal Name as String, ...)
if (flags and FieldsToUpdate.active)=active then
'...
end if
if (flags and FieldsToUpdate.name) = name then
'...
end if
end sub
Another sub making this easier would help, so you'd only have to write one
line per field.
well, you could also declare the arguments As Object, so you'll be able
to pass Nothing, but you'll loose type safety which should usually be
preferred over simplification.
Depending on the current (and future) structure of your application and the
level of database integration, there, of course, can also better approaches.