Пример #1
0
        public DateTime GetDateTime(int index)
        {
            MySqlValue fieldValue = this.GetFieldValue(index, true);

            if (fieldValue is MySqlDateTime)
            {
                MySqlDateTime mySqlDateTime = (MySqlDateTime)fieldValue;
                if (this.connection.Settings.ConvertZeroDateTime && !mySqlDateTime.IsValidDateTime)
                {
                    return(DateTime.MinValue);
                }
                return(mySqlDateTime.GetDateTime());
            }
            else
            {
                if (!(fieldValue is MySqlString))
                {
                    throw new NotSupportedException("Unable to convert from type " + fieldValue.GetType().ToString() + " to DateTime");
                }
                MySqlDateTime mySqlDateTime2 = new MySqlDateTime(MySqlDbType.Datetime);
                mySqlDateTime2 = mySqlDateTime2.ParseMySql(this.GetString(index), true);
                return(mySqlDateTime2.GetDateTime());
            }
        }
Пример #2
0
        /// <include file='docs/MySqlDataReader.xml' path='docs/GetDateTime/*'/>
        public DateTime GetDateTime(int index)
        {
            MySqlValue val = GetFieldValue(index);

            if (val is MySqlDateTime)
            {
                MySqlDateTime dt = (MySqlDateTime)val;
                if (connection.Settings.ConvertZeroDateTime && !dt.IsValidDateTime)
                {
                    return(DateTime.MinValue);
                }
                else
                {
                    return(dt.GetDateTime());
                }
            }
            else if (val is MySqlString)
            {
                MySqlDateTime d = new MySqlDateTime(MySqlDbType.Datetime);
                d = d.ParseMySql((val as MySqlString).Value, true);
                return(d.GetDateTime());
            }
            throw new NotSupportedException("Unable to convert from type " + val.GetType().ToString() + " to DateTime");
        }