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


C# MySqlCommand.ExecuteReaderAsync方法代码示例

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


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

示例1: getMaxAsync

        public async Task<int> getMaxAsync(String tableName,String id)
        {
            int max = 0;
            using (MySqlConnection MidbConexion = new MySqlConnection(this.dbPath))
            {
                MidbConexion.Open();
                MySqlCommand miComando = new MySqlCommand()
                {
                    Connection = MidbConexion,
                    CommandText = String.Format("SELECT Max({0}) AS MAXIMO FROM {1}", id, tableName)

                };
                var  reader = await miComando.ExecuteReaderAsync();
                while (reader.Read())
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("Maximo")))
                    {
                        max = Convert.ToInt32(reader[0]) + 1;
                    }
                    else
                    {
                        max = 1;
                    }
                }


            }
            return max;


        }
开发者ID:oscarito9410,项目名称:wpHotel,代码行数:31,代码来源:ICrudHelper.cs

示例2: FetchArrayList

 public static async Task<List<object>> FetchArrayList(string query) {
     var list = new List<object>();
     using (var command = new MySqlCommand(query, Connection)) {
         using (var reader = await command.ExecuteReaderAsync()) {
             while (reader.Read()) {
                 for (var i = 0; i < reader.FieldCount; i++) {
                     var value = reader[i];
                     list.Add(value);
                 }
             }
         }
     }
     return list;
 }
开发者ID:Hotallday,项目名称:iXat-Server,代码行数:14,代码来源:Database.cs

示例3: FetchArray

 public static async Task<Dictionary<string, object>> FetchArray(string query) {
     var dictionary = new Dictionary<string, object>();
     using (var command = new MySqlCommand(query, Connection)) {
         using (var reader = await command.ExecuteReaderAsync()) {
             while (reader.Read()) {
                 for (var i = 0; i < reader.FieldCount; i++) {
                     var key = reader.GetName(i);
                     var value = reader[i];
                     dictionary.Add(key, value);
                 }
             }
         }
     }
     return dictionary;
 }
开发者ID:Hotallday,项目名称:iXat-Server,代码行数:15,代码来源:Database.cs

示例4: GetOverallDuration

        private async void GetOverallDuration()
        {
            int calculatedaverage = new Int32();
            MySqlDataReader dbReader = null;

            using (MySqlConnection dbConn = new MySqlConnection("Server=" + ICResponse.Properties.Settings.Default.DBServer +
                                                ";Database=" + ICResponse.Properties.Settings.Default.DBName +
                                                ";Uid=" + ICResponse.Properties.Settings.Default.DBUser +
                                                ";Pwd=" + ICResponse.Properties.Settings.Default.DBPass + ";"))
            {
                dbConn.Open();
                using (MySqlCommand cmd = new MySqlCommand(ICResponse.Properties.Settings.Default.GetOverallAverageTime, dbConn))
                {
                    dbReader = (MySqlDataReader)await cmd.ExecuteReaderAsync();
                    while (dbReader.Read())
                    {
                        int receivedaverage = Convert.ToInt32(dbReader["OverallAverageDuration"]);
                        calculatedaverage = (receivedaverage / 60);
                    }
                }
                dbConn.Close();
            }           
            
            ATT.Content = Convert.ToString(calculatedaverage);
            if (calculatedaverage >= 20)
            {
                ATT.Foreground = Brushes.Red;
            }
            if (calculatedaverage < 20 && calculatedaverage > 10)
            {
                ATT.Foreground = Brushes.Yellow;
            }
            if (calculatedaverage <= 10)
            {
                ATT.Foreground = Brushes.Chartreuse;
            }
        }
开发者ID:Toffer305,项目名称:icresponse2,代码行数:37,代码来源:OverviewStatus.xaml.cs

示例5: GetAgentStats

        private async void GetAgentStats()
        {
            try
            {
                MySqlConnection dbConn = null;
                MySqlDataReader dbReader = null;
                string receivedemail = string.Empty;
                int receivedNumOfRows = 0;
                _counts.Clear();
                _times.Clear();
                _missed.Clear();
                using (dbConn = new MySqlConnection("Server=" + ICResponse.Properties.Settings.Default.DBServer +
                                                ";Database=" + ICResponse.Properties.Settings.Default.DBName +
                                                ";Uid=" + ICResponse.Properties.Settings.Default.DBUser +
                                                ";Pwd=" + ICResponse.Properties.Settings.Default.DBPass + ";"))
                {
                    dbConn.Open();

                    using (MySqlCommand cmd = new MySqlCommand(ICResponse.Properties.Settings.Default.GetGroupedCalls, dbConn))
                    {
                        dbReader = (MySqlDataReader)await cmd.ExecuteReaderAsync();
                        while (dbReader.Read())
                        {
                            receivedemail = Convert.ToString(dbReader["tech"]);
                            string formalname = GetAgentACDname(receivedemail);
                            receivedNumOfRows = Convert.ToInt32(dbReader["NumOfRows"]);
                            int averageduration = Convert.ToInt32(dbReader["TechAverageDuration"]);
                            int convertedduration = (averageduration / 60);
                            int missedcounts = GetAgentMissedCalls(formalname);                            

                            _counts.Add(new DailyAgent() { Agent = formalname, Count = receivedNumOfRows });
                            _times.Add(new DailyAgent() { Agent = formalname, Count = convertedduration });
                            _missed.Add(new DailyAgent() { Agent = formalname, Count = missedcounts });                            
                        }
                    }
                    dbReader.Close();
                    dbConn.Close();
                }               
            }
            catch (MySqlException err)
            {
                System.Diagnostics.Debug.WriteLine(err);
            }
        }
开发者ID:Toffer305,项目名称:icresponse2,代码行数:44,代码来源:AgentStats.xaml.cs

示例6: getAll

        public async Task<ObservableCollection<Model.Cliente>> getAll()
        {
            ObservableCollection<Model.Cliente> listClientes = new ObservableCollection<Model.Cliente>();

            using (MySqlConnection MidbConexion = new MySqlConnection(this.dbPath))
            {
                MidbConexion.Open();
                MySqlCommand miComando = new MySqlCommand()
                {
                    Connection = MidbConexion,
                    CommandText = String.Format("SELECT*FROM cliente_detalles")
                };
                var reader =await miComando.ExecuteReaderAsync();
                while (reader.Read())
                {
                    Model.Cliente cliente = new Model.Cliente();
                    cliente.id = Convert.ToInt32(reader["id_cliente"]);
                    cliente.acompaniantes =Convert.ToInt32(reader["numpersonas"]);
                    cliente.nombre = Convert.ToString(reader["nombre"]);
                    cliente.origen = Convert.ToString(reader["lugar_procedencia"]);
                    cliente.email = Convert.ToString(reader["correo"]);
                    cliente.tarjeta = Convert.ToString(reader["numtarjeta"]);
                    cliente.dateEntrada= Convert.ToDateTime(reader["dia_entrada"]);
                    cliente.dateSalida = Convert.ToDateTime(reader["dia_salida"]);
                    cliente.diasEstancia = getDias(cliente.dateEntrada, cliente.dateSalida);
                    cliente.email = Convert.ToString(reader["correo"]);
                    cliente.telefono = Convert.ToString(reader["telefono"]);
                    
                    listClientes.Add(cliente);

                }
                return listClientes;

            }
        }
开发者ID:oscarito9410,项目名称:wpHotel,代码行数:35,代码来源:CrudCliente.cs

示例7: getClienteGasto

        public async Task<int> getClienteGasto(int idCliente)
        {
            int clave = 1;
            using (MySqlConnection MidbConexion = new MySqlConnection(this.dbPath))
            {
                MidbConexion.Open();
                MySqlCommand miComando = new MySqlCommand()
                {
                    Connection = MidbConexion,
                    CommandText = String.Format("SELECT clv_gasto AS Clave FROM gastos WHERE id_cliente=?id_cliente")
                };
                miComando.Parameters.AddWithValue("?id_cliente", idCliente);
                var reader = await miComando.ExecuteReaderAsync();
                while (reader.Read())
                {
                    if (!reader.IsDBNull(reader.GetOrdinal("Clave")))
                    {
                        clave = Convert.ToInt32(reader[0]);
                    }
                }

            }
            return clave;
        }
开发者ID:oscarito9410,项目名称:wpHotel,代码行数:24,代码来源:CrudCliente.cs

示例8: getHabitacionesDisponibles

        public async Task<ObservableCollection<Model.Habitacion>> getHabitacionesDisponibles(String tamanio)
        {
            ObservableCollection<Model.Habitacion> listHabitaciones = new ObservableCollection<Model.Habitacion>();

            using (MySqlConnection MidbConexion = new MySqlConnection(this.dbPath))
            {
                MidbConexion.Open();
                MySqlCommand miComando = new MySqlCommand()
                {
                    Connection = MidbConexion,
                    CommandText = String.Format("SELECT*FROM view_disponibles WHERE tamanio='{0}'", tamanio)
                };
                 var  reader = await miComando.ExecuteReaderAsync();
                while (reader.Read())
                {
                    Model.Habitacion habitacion = new Model.Habitacion();
                    habitacion.numero = Convert.ToInt32(reader["num_habitacion"]);
                    habitacion.estado = true;
                    habitacion.tamanio = Convert.ToString(reader["tamanio"]);
                    habitacion.telefono = Convert.ToString(reader["telefono"]);
                    habitacion.precio = Convert.ToDouble(reader["precio"]);
                    listHabitaciones.Add(habitacion);

                }
                return listHabitaciones;

            }
        }
开发者ID:oscarito9410,项目名称:wpHotel,代码行数:28,代码来源:ICrudHelper.cs

示例9: Execute

        /// <summary>
        /// Execute a SQL prepared statement on the database.
        /// </summary>
        /// <param name="stmt"></param>
        /// <returns></returns>
        public async Task<DataTable> Execute(MySqlCommand stmt, bool enforceConstraints = true, string[] pKeys = null)
        {
            DataTable result = null;
            if (connState == ConnectionState.Open)
            {
                using (DbDataReader reader = await stmt.ExecuteReaderAsync())
                {
                    var dt = new DataTable();
                    if (!enforceConstraints)
                    {
                        var ds = new DataSet();
                        ds.EnforceConstraints = false;
                        ds.Tables.Add(dt);
                    }

                    if (pKeys != null)
                    {
                        DataColumn[] keys = new DataColumn[pKeys.Length];
                        for (int i = 0; i < pKeys.Length; i++)
                        {
                            dt.Columns.Add(pKeys[i]);
                            keys[i] = dt.Columns[pKeys[i]];
                        }
                        dt.PrimaryKey = keys;
                    }

                    dt.Load(reader);
                    result = dt;
                }
            }
            return result;
        }
开发者ID:imbavirus,项目名称:TrinityCoreAdmin,代码行数:37,代码来源:MySQLConnection.cs

示例10: GetUserRole

        public async Task<IList<string>> GetUserRole(int userId)
        {
            IList<string> roles = new List<string>();

            string query = @"SELECT
                                Role
                             FROM 
                                userrole
                              WHERE
                                UserId = ?UserId;";


            MySqlCommand command = new MySqlCommand();

            command.CommandText = query;

            command.Parameters.AddWithValue("UserId", userId);

            using (MySqlConnection connection = (MySqlConnection)await _connectionProvider.GetAsync())
            {
                command.Connection = connection;
                await connection.OpenAsync();

                using (var reader = await command.ExecuteReaderAsync())
                {
                    while (reader.Read())
                    {
                        roles.Add(reader.GetString(0));
                    }
                }

                await connection.CloseAsync();
            }

            return roles;

        }
开发者ID:GNewsCo,项目名称:DrawPub,代码行数:37,代码来源:UserRepository.cs

示例11: attemptLogin

        private async void attemptLogin()
        {
            try
            {
                string enteredEmail = this.Login_Email.Text + "@icrealtime.com";
                string enteredPassword = this.Login_Password.Password;
                string receivedPassword = string.Empty;
                string receivedLevel = string.Empty;

                // DB Connection
                dbConn = new MySqlConnection("Server=" + ICResponse.Properties.Settings.Default.DBServer + ";Database=" + ICResponse.Properties.Settings.Default.DBName + ";Uid=" + ICResponse.Properties.Settings.Default.DBUser + ";Pwd=" + ICResponse.Properties.Settings.Default.DBPass + ";");
                await dbConn.OpenAsync();
                // DB Command Preparation
                cmd = new MySqlCommand(ICResponse.Properties.Settings.Default.SelectAgentByEmail, dbConn);
                cmd.Parameters.AddWithValue("@email", enteredEmail);
                cmd.Prepare();
                // DB Reader Execution
                dbReader = (MySqlDataReader) await cmd.ExecuteReaderAsync();
                // Loop through results
                while (await dbReader.ReadAsync())
                {
                    receivedPassword = Convert.ToString(dbReader["password"]);
                    receivedLevel = Convert.ToString(dbReader["level"]);
                }

                if (enteredPassword != receivedPassword)
                {
                    ModernDialog msgbox = new ModernDialog();
                    msgbox.Title = "Not found";
                    msgbox.Content = "Incorrect Username or Password.";
                    msgbox.Buttons = new[] { msgbox.OkButton };
                    msgbox.ShowDialog();
                    dbReader.Close();
                }
                else
                {
                    ICResponse.Properties.Settings.Default.LoginUsername = Convert.ToString(dbReader["email"]);
                    ICResponse.Properties.Settings.Default.AgentID = Convert.ToInt32(dbReader["agentID"]);
                    ICResponse.Properties.Settings.Default.AgentFirstName = Convert.ToString(dbReader["first"]);
                    ICResponse.Properties.Settings.Default.AgentLastName = Convert.ToString(dbReader["last"]);
                    ICResponse.Properties.Settings.Default.LoginPassword = receivedPassword;
                    ICResponse.Properties.Settings.Default.LoginLevel = receivedLevel;
                    ICResponse.Properties.Settings.Default.LoginNick = ICResponse.Properties.Settings.Default.LoginUsername.Replace("@icrealtime.com", "");
                    ICResponse.Properties.Settings.Default.Save();
                    dbReader.Close();

                    var mainWindow = new MainWindow();
                    var loginWindow = Window.GetWindow(this);
                    mainWindow.Show();
                    if (loginWindow != null) loginWindow.Close();
                }

            }
            catch (MySqlException err)
            {
                System.Diagnostics.Debug.WriteLine(err);
            }
            finally
            {
                if (dbConn != null)
                {
                    dbConn.Close(); //close the connection
                }
            }
        }
开发者ID:Toffer305,项目名称:icresponse2,代码行数:65,代码来源:LogIn.xaml.cs

示例12: ReadStateAsync

        public async Task ReadStateAsync(string grainType, GrainReference grainReference, GrainState grainState)
        {
            var con = await GetFreeConnection();

            var table = GetTableName(grainState);
            string keyAsString = GetKey(grainReference);

            string query;

            if (CustomTable)
                query = string.Format("select * from `{0}` where `guid` = \"{1}\";", table,
                    MySqlHelper.EscapeString(keyAsString));
            else
                query = string.Format("select * from `{0}` where `guid` = \"{1}\" AND `type` = \"{2}\";", table,
                    MySqlHelper.EscapeString(keyAsString), MySqlHelper.EscapeString(grainType));

            using (var cmd = new MySqlCommand(query, con))
            {
                using (var reader = await cmd.ExecuteReaderAsync())
                {
                    if (await reader.ReadAsync())
                    {
                        Dictionary<string, object> dict = new Dictionary<string, object>();

                        for (int i = 0; i < reader.FieldCount; ++i)
                            dict.Add(reader.GetName(i), reader.GetValue(i));

                        if (dict.ContainsKey("data"))
                        {
                            try
                            {
                                var data =
                                    (GrainState)
                                        Newtonsoft.Json.JsonConvert.DeserializeObject(dict["data"].ToString(),
                                            grainState.GetType());
                                grainState.SetAll(data.AsDictionary());
                            }
                            catch
                            {
                                grainState.SetAll(null); /* corruption? */
                            }
                        }
                        else
                            grainState.SetAll(null);
                    }
                }
            }

            await AddFreeConnection(con);
        }
开发者ID:andy012345,项目名称:WoWServer,代码行数:50,代码来源:OrleansMySQLJSONStorage.cs

示例13: GetCallVolumes

        private async void GetCallVolumes()
        {
            try
            {
                MySqlConnection dbConn = null;
                MySqlDataReader dbReader = null;
                string receivedDT = string.Empty;
                DateTime receivedtime = DateTime.Now;
                int nine2ten = 0;
                int ten2eleven = 0;
                int eleven2twelve = 0;
                int twelve2thirteen = 0;
                int thirteen2fourteen = 0;
                int fourteen2fifteen = 0;
                int fifteen2sixteen = 0;
                int sixteen2seventeen = 0;
                int seventeen2eighteen = 0;
                int eighteen2nineteen = 0;
                int nineteen2twenty = 0;
                int twenty2twentyone = 0;
                _volume.Clear();
                volumebyHour.Clear();

                using (dbConn = new MySqlConnection("Server=" + ICResponse.Properties.Settings.Default.DBServer +
                                                ";Database=" + ICResponse.Properties.Settings.Default.DBName +
                                                ";Uid=" + ICResponse.Properties.Settings.Default.DBUser +
                                                ";Pwd=" + ICResponse.Properties.Settings.Default.DBPass + ";"))
                {
                    dbConn.Open();
                    using (MySqlCommand cmd = new MySqlCommand(ICResponse.Properties.Settings.Default.GetCallVolume, dbConn))
                    {
                        dbReader = (MySqlDataReader)await cmd.ExecuteReaderAsync();
                        while (dbReader.Read())
                        {
                            receivedDT = Convert.ToString(dbReader["startTime"]);
                            receivedtime = DateTime.Parse(receivedDT);
                            volumebyHour.Add(receivedtime);
                        }
                    }                    
                    dbReader.Close();
                    dbConn.Close();

                    for (int i = 0; i < volumebyHour.Count; i++)
                    {
                        int hourcomponent = Int32.Parse(volumebyHour[i].Hour.ToString()); 
                        switch (hourcomponent)
                        {
                            case 9:
                                nine2ten++;
                                break;
                            case 10:
                                ten2eleven++;
                                break;
                            case 11:
                                eleven2twelve++;
                                break;
                            case 12:
                                twelve2thirteen++;
                                break;
                            case 13:
                                thirteen2fourteen++;
                                break;
                            case 14:
                                fourteen2fifteen++;
                                break;
                            case 15:
                                fifteen2sixteen++;
                                break;
                            case 16:
                                sixteen2seventeen++;
                                break;
                            case 17:
                                seventeen2eighteen++;
                                break;
                            case 18:
                                eighteen2nineteen++;
                                break;
                            case 19:
                                nineteen2twenty++;
                                break;
                            case 20:
                                twenty2twentyone++;
                                break;
                            default:
                                break;
                        }
                    }
                }
                
                _volume.Add(new CallVolumeChart() { Time = "Nine", Count = nine2ten });
                _volume.Add(new CallVolumeChart() { Time = "Ten", Count = ten2eleven });
                _volume.Add(new CallVolumeChart() { Time = "Eleven", Count = eleven2twelve });
                _volume.Add(new CallVolumeChart() { Time = "Twelve", Count = twelve2thirteen });
                _volume.Add(new CallVolumeChart() { Time = "One", Count = thirteen2fourteen });
                _volume.Add(new CallVolumeChart() { Time = "Two", Count = fourteen2fifteen });
                _volume.Add(new CallVolumeChart() { Time = "Three", Count = fifteen2sixteen });
                _volume.Add(new CallVolumeChart() { Time = "Four", Count = sixteen2seventeen });
                _volume.Add(new CallVolumeChart() { Time = "Five", Count = seventeen2eighteen });
                _volume.Add(new CallVolumeChart() { Time = "Six", Count = eighteen2nineteen });
                _volume.Add(new CallVolumeChart() { Time = "Seven", Count = nineteen2twenty });
//.........这里部分代码省略.........
开发者ID:Toffer305,项目名称:icresponse2,代码行数:101,代码来源:CallVolume.xaml.cs


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