Insert NULL into SQL when string is empty
Setting an empty string to null on Insert into database
/// <summary> /// Databases the null if null. /// </summary> /// <param name="obj">The object.</param> /// <returns>returns object</returns> public static object DBNullIfNull(object obj) { return obj != null ? obj : DBNull.Value; } /// <summary> /// Databases the null if null or empty. /// </summary> /// <param name="str">The string.</param> /// <returns>returns object</returns> public static object DBNullIfNullOrEmpty(string str) { return !String.IsNullOrEmpty(str) ? str : (object)DBNull.Value; }
Insert NULL into SQL when string is empty
Reviewed by Bhaumik Patel
on
7:36 PM
Rating:
