DbParameter param = comm.CreateParameter();
param = comm.CreateParameter();
param.ParameterName = "@StaffId";
if (!string.IsNullOrEmpty(activity.StaffId))
param.Value = activity.StaffId;
param.DbType = DbType.String;
comm.Parameters.Add(param);
The above does not work (obviously), object not instantiated. I am attempting to insert a NULL into the database when StaffId is NOT populated. How can I achieve this?
You could use
DBNull.Value
:You can always use the null-coalescing operator (??)
Try
DBNull.Value
You can use DBNull.Value when you need to pass NULL as a parameter to the stored procedure.
Or you can use that instead of your
if
operator: