Nullable SqlParameter passing a null

To pass a value that could be null use the following:

int? recordID = null;
var parameter = new System.Data.SqlClient.SqlParameter {
                    ParameterName = "@id", 
                    SqlDbType = SqlDbType.Int, 
                    Value = (object)recordID ?? DBNull.Value, 
                };

Comments are closed.