Let's say I have a MySql stored procedure that inserts a record with some nullable CHAR fields.
In VB.NET if I don't check for Nothing (or Null in other languages), I get an exception from the db driver, so I write:
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("_name", if(name Is Nothing, "", name)).Direction = ParameterDirection.Input;
And this is the first thing I don't like; I'd like to pass Nothing and the driver knows it has to put NULL in the Db. But then, in the stored procedure, I have to check back the field if it is empty:
INSERT INTO mytable
(
name,
-- other 200 char fields
)
VALUES
(
NULLIF(_name, ''),
-- other 200 char fields
)
Ugly uh? I have to check for nothingness/emptiness twice. Is there a better, more direct, way?
Even worse, for non reference types (i.e: Integers) the check for nothingness makes no sense, since a primitive type can't be nothing (yes, I could set an Integer to a non meaningful value, say -1 for a positive id, but...).