ForDatabase

public static class StringExtensions
{
    public static object ForDatabase(this string str)
    {
        if (str == null)
        {
            return System.DBNull.Value;
        }

        return str;
    }
}
Example:
SqlCommand command = new SqlCommand(commandText, connection);
command.Parameters.Add(new SqlParameter("@Email",email.ForDatabase());

Description

For use with old school ado.net database command parameters. This basically converts the string to System.DBNull.Value if the string is null else it returns the string.

Details

Double click on the code to select all.

 

;