System.Data.Common.SqlConvert.ConvertToSqlDateTime C# (CSharp) Method

ConvertToSqlDateTime() public static method

public static ConvertToSqlDateTime ( object value ) : SqlDateTime
value object
return System.Data.SqlTypes.SqlDateTime
        public static SqlDateTime ConvertToSqlDateTime(object value)
        {
            Debug.Assert(value != null, "null argument in ConvertToSqlDateTime");
            if (value == DBNull.Value)
            {
                return SqlDateTime.Null;
            }
            Type valueType = value.GetType();
            StorageType stype = DataStorage.GetStorageType(valueType);

            switch (stype)
            {
                case StorageType.SqlDateTime:
                    return (SqlDateTime)value;
                case StorageType.DateTime:
                    return (DateTime)value;
                default:
                    throw ExceptionBuilder.ConvertFailed(valueType, typeof(SqlDateTime));
            }
        }

Usage Example

Esempio n. 1
0
 public override object ConvertValue(object?value)
 {
     if (null != value)
     {
         return(SqlConvert.ConvertToSqlDateTime(value));
     }
     return(_nullValue);
 }
All Usage Examples Of System.Data.Common.SqlConvert::ConvertToSqlDateTime