當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。