@Tom Halladay's answer is correct with the mention that you shopuld also check for null values and send DbNullable if params are null as you would get an exception like
The parameterized query '...' expects the parameter '@parameterName', which was not supplied.
Something like this helped me
public static object GetDBNullOrValue<T>(this T val)
{
bool isDbNull = true;
Type t = typeof(T);
if (Nullable.GetUnderlyingType(t) != null)
isDbNull = EqualityComparer<T>.Default.Equals(default(T), val);
else if (t.IsValueType)
isDbNull = false;
else
isDbNull = val == null;
return isDbNull ? DBNull.Value : (object) val;
}
(credit for the method goes to https://stackoverflow.com/users/284240/tim-schmelter)
Then use it like:
new SqlParameter("@parameterName", parameter.GetValueOrDbNull())
or another solution, more simple, but not generic would be:
new SqlParameter("@parameterName", parameter??(object)DBNull.Value)