当前位置: 首页>>代码示例>>C#>>正文


C# MySqlDataReader.GetMySqlDateTime方法代码示例

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlDataReader.GetMySqlDateTime方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlDataReader.GetMySqlDateTime方法的具体用法?C# MySqlDataReader.GetMySqlDateTime怎么用?C# MySqlDataReader.GetMySqlDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySql.Data.MySqlClient.MySqlDataReader的用法示例。


在下文中一共展示了MySqlDataReader.GetMySqlDateTime方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMySQLDateTime

        public static DateTime GetMySQLDateTime(MySqlDataReader mySQLDataReader, String column)
        {
            DateTime dateTime = DateTime.MinValue;

            try
            {
                int index = mySQLDataReader.GetOrdinal(column);
                if (!mySQLDataReader.IsDBNull(index))
                {
                    MySqlDateTime mySQLDateTime = mySQLDataReader.GetMySqlDateTime(column);
                    if (mySQLDateTime.Day > 0)
                    {
                        dateTime = mySQLDateTime.GetDateTime();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }

            return dateTime;
        }
开发者ID:seifeet,项目名称:schoolparser,代码行数:23,代码来源:MySQLReader.cs

示例2: readEntry

        private TrackingEntry readEntry(MySqlDataReader reader)
        {
            TrackingEntry currentEntry = new TrackingEntry();

            currentEntry.entryID = reader.GetInt32(0);
            currentEntry.taggerID = reader.GetInt32(1);
            currentEntry.type = reader.GetChar(2);
            currentEntry.isTagged = reader.GetBoolean(3);
            currentEntry.taggerName = reader.GetString(4);
            currentEntry.entryDate = ((DateTime)reader.GetMySqlDateTime(5)).ToString("yyyy-MM-dd HH:mm:ss");

            if (reader.IsDBNull(6))
                currentEntry.tagNumber = -1;
            else
                currentEntry.tagNumber = reader.GetInt32(6);

            currentEntry.species = reader.GetString(7);

            if (reader.IsDBNull(8))
                currentEntry.city = "";
            else
                currentEntry.city = reader.GetString(8);

            if (reader.IsDBNull(9))
                currentEntry.state = "";
            else
                currentEntry.state = reader.GetString(9);

            if (reader.IsDBNull(10))
                currentEntry.country = "";
            else
                currentEntry.country = reader.GetString(10);

            if (reader.IsDBNull(11))
                currentEntry.longitude = "";
            else
                currentEntry.longitude = reader.GetString(11);

            if (reader.IsDBNull(12))
                currentEntry.latitude = "";
            else
                currentEntry.latitude = reader.GetString(12);

            if (reader.IsDBNull(13))
                currentEntry.temperature = "";
            else
                currentEntry.temperature = reader.GetString(13);

            if (reader.IsDBNull(14))
                currentEntry.precipitation = "";
            else
                currentEntry.precipitation = reader.GetString(14);

            if (reader.IsDBNull(15))
                currentEntry.windSpeed = "";
            else
                currentEntry.windSpeed = reader.GetString(15);

            if (reader.IsDBNull(16))
                currentEntry.windDirection = "";
            else
                currentEntry.windDirection = reader.GetString(16);

            return currentEntry;
        }
开发者ID:gsohal,项目名称:ButterflyTrackingSystem,代码行数:65,代码来源:TrackingEntryQuery.cs

示例3: ConvertToSqlFormat


//.........这里部分代码省略.........
            {
                sb.AppendFormat(((byte)ob).ToString(_numberFormatInfo));
            }
            else if (ob is sbyte)
            {
                sb.AppendFormat(((sbyte)ob).ToString(_numberFormatInfo));
            }
            else if (ob is TimeSpan)
            {
                TimeSpan ts = (TimeSpan)ob;

                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");

                sb.AppendFormat(ts.Hours.ToString().PadLeft(2, '0'));
                sb.AppendFormat(":");
                sb.AppendFormat(ts.Minutes.ToString().PadLeft(2, '0'));
                sb.AppendFormat(":");
                sb.AppendFormat(ts.Seconds.ToString().PadLeft(2, '0'));

                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");
            }
            else if (ob is System.DateTime)
            {
                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");

                sb.AppendFormat(((DateTime)ob).ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));

                if (col.TimeFractionLength > 0)
                {
                    sb.Append(".");
                    string _microsecond = rdr.GetMySqlDateTime(colIndex).Microsecond.ToString();
                    if (_microsecond.Length < col.TimeFractionLength)
                    {
                        _microsecond = _microsecond.PadLeft(col.TimeFractionLength, '0');
                    }
                    else if (_microsecond.Length > col.TimeFractionLength)
                    {
                        _microsecond = _microsecond.Substring(0, col.TimeFractionLength);
                    }
                    sb.Append(_microsecond.ToString().PadLeft(col.TimeFractionLength, '0'));
                }

                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");
            }
            else if (ob is MySql.Data.Types.MySqlDateTime)
            {
                MySql.Data.Types.MySqlDateTime mdt = (MySql.Data.Types.MySqlDateTime)ob;

                if (mdt.IsNull)
                {
                    sb.AppendFormat("NULL");
                }
                else
                {
                    if (mdt.IsValidDateTime)
                    {
                        DateTime dtime = mdt.Value;

                        if (wrapStringWithSingleQuote)
                            sb.AppendFormat("'");

                        if (col.MySqlDataType == "datetime")
开发者ID:njmube,项目名称:Mysqlbackup.net,代码行数:67,代码来源:QueryExpress.cs

示例4: CleanInactiveUsers

        public static void CleanInactiveUsers()
        {
            CloseReader();

            Logger.Log(LogType.Event, "Clearing inactive users from database");
            try
            {
                string query = String.Format(
                    "SELECT * FROM {0} WHERE (Active='0')",
                    playerTableName);

                MySqlCommand cmd = new MySqlCommand(query, dbConnection);
                dbReader = cmd.ExecuteReader();

                while (dbReader.Read())
                {
                    string name = dbReader.GetString("Name");
                    string email = dbReader.GetString("Email");
                    DateTime time = dbReader.GetMySqlDateTime("RegDate").GetDateTime();
                    if (time.AddDays(Properties.Settings.Default.playerinactivelimit).CompareTo(DateTime.Now) < 0)
                    {
                        query = String.Format(
                            "DELETE FROM {0} WHERE (Name='{1:0}')",
                            playerTableName, name);

                        cmd = new MySqlCommand(query, dbConnection);
                        dbReader = cmd.ExecuteReader();
                        CloseReader();

                        Logger.Log(LogType.Event, name + " was deleted from database due to inactivity");

                        Email(
                        "Poker Account Expired",
                        String.Format(
                            "Hello, your account ({0}) on Circle of Current Poker has expired.",
                            name),
                        email
                        );
                    }
                }

                CloseReader();
            }
            catch (Exception ex)
            {
                Logger.Log("While cleaning inactive users", ex);
            }
        }
开发者ID:quicklywilliam,项目名称:circle-of-current,代码行数:48,代码来源:Database.cs

示例5: updateDateValue

        public void updateDateValue(String tabela, String campo, OleDbCommand comandoTarget, MySqlDataReader reader, Int16 index, String campoId, Int32 valorId)
        {
            if (!reader.IsDBNull(index))
            {
                comandoTarget.CommandText = "Update " + tabela + " set " + campo + "=cdate('" + reader.GetMySqlDateTime(index) + "') where " + campoId + " = " + valorId; ;
                comandoTarget.ExecuteNonQuery();

            }
        }
开发者ID:pctjose,项目名称:OpenMRStoACCESS,代码行数:9,代码来源:InsertUtils.cs

示例6: readToUser

        private List<User> readToUser(MySqlDataReader _reader)
        {
            List<User> users = new List<User>();
            string usersQuery = String.Format("SELECT user_type, {0}.users.id, Username, name, dateOfBirth, surname, gender, password, length, weight FROM {0}.users LEFT JOIN {0}.client_bmi_info on {0}.users.id = {0}.client_bmi_info.users_id  ", _database);
            OpenConnection();
            _selectCommand = new MySqlCommand(usersQuery, Connection);


            while (_reader.Read())
            {
                User u;
                int type = _reader.GetInt32(0);
                if (type == 2)
                {
                    u = new Administrator()
                    {
                        Username = _reader.IsDBNull(2) ? null : _reader.GetString(2),
                        Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5),
                        Name = _reader.IsDBNull(3) ? null : _reader.GetString(3),
                        DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4),
                        Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1),
                        Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6)
                    };
                }
                else if (type == 1)
                {
                    u = new Specialist
                    {
                        Username = _reader.IsDBNull(2) ? null : _reader.GetString(2),
                        Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5),
                        Name = _reader.IsDBNull(3) ? null : _reader.GetString(3),
                        DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4),
                        Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1),
                        Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6)
                    };
                }
                else if (_reader.GetInt32(0) == 0)
                {
                    u = new Client
                    {
                        Username = _reader.IsDBNull(2) ? null : _reader.GetString(2),
                        Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5),
                        Name = _reader.IsDBNull(3) ? null : _reader.GetString(3),
                        DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4),
                        Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1),
                        Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6),
                        Lenght = _reader.IsDBNull(8) ? -1 : _reader.GetDecimal(8),
                        Weight = _reader.IsDBNull(9) ? -1 : _reader.GetDecimal(9)
                    };
                }
                else
                    continue;
                users.Add(u);
            }
            _reader.Close();
            return users;
        }
开发者ID:JordySipkema,项目名称:LD326_RH_A5,代码行数:57,代码来源:DBConnect.cs


注:本文中的MySql.Data.MySqlClient.MySqlDataReader.GetMySqlDateTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。