Beispiel #1
0
        private static DataTable Read(Statment statement)
        {
            DataTable retVal = new DataTable();

            using (MySqlConnection c = new MySqlConnection(strConnection))
            {
                c.Open();
                using (MySqlCommand cmd = c.CreateCommand())
                {
                    cmd.CommandTimeout = 0; // No timeout
                    cmd.CommandText    = statement.query;
                    foreach (KeyValuePair <string, object> entry in statement.parameters)
                    {
                        cmd.Parameters.AddWithValue(entry.Key, entry.Value);
                    }
                    cmd.Prepare();
                    try
                    {
                        retVal.Load(cmd.ExecuteReader());
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError("Error while executing query: " + ex.Message);
                    }
                    statement.Dispose();
                }
            }
            return(retVal);
        }
Beispiel #2
0
 private static void Query(Statment statement)
 {
     using (MySqlConnection c = new MySqlConnection(strConnection))
     {
         c.Open();
         using (MySqlCommand cmd = c.CreateCommand())
         {
             cmd.CommandTimeout = 0; // No timeout
             cmd.CommandText    = statement.query;
             foreach (KeyValuePair <string, object> entry in statement.parameters)
             {
                 cmd.Parameters.AddWithValue(entry.Key, entry.Value);
             }
             try
             {
                 cmd.Prepare();
                 cmd.ExecuteNonQuery();
             }
             catch (Exception ex)
             {
                 Log.WriteError("Error while executing query: " + ex.Message);
             }
             statement.Dispose();
         }
     }
 }
Beispiel #3
0
        private static void QueryAsync(Statment statement)
        {
            MySqlConnection c = new MySqlConnection(strConnection);

            c.Open();
            MySqlCommand cmd = c.CreateCommand();

            cmd.CommandText = statement.query;
            foreach (KeyValuePair <string, object> entry in statement.parameters)
            {
                cmd.Parameters.AddWithValue(entry.Key, entry.Value);
            }
            cmd.Prepare();
            cmd.BeginExecuteNonQuery(new AsyncCallback(QueryAsyncCallback), new QueryObject <bool>(null, cmd));
        }
Beispiel #4
0
 private static void Query(Statment statement)
 {
     using (MySqlConnection c = new MySqlConnection(strConnection))
     {
         c.Open();
         using (MySqlCommand cmd = c.CreateCommand())
         {
             cmd.CommandText = statement.query;
             foreach (KeyValuePair <string, object> entry in statement.parameters)
             {
                 cmd.Parameters.AddWithValue(entry.Key, entry.Value);
             }
             cmd.Prepare();
             cmd.ExecuteNonQuery();
         }
     }
 }
Beispiel #5
0
        private static DataTable Read(Statment statement)
        {
            DataTable retVal = new DataTable();

            using (MySqlConnection c = new MySqlConnection(strConnection))
            {
                c.Open();
                using (MySqlCommand cmd = c.CreateCommand())
                {
                    cmd.CommandText = statement.query;
                    foreach (KeyValuePair <string, object> entry in statement.parameters)
                    {
                        cmd.Parameters.AddWithValue(entry.Key, entry.Value);
                    }
                    cmd.Prepare();
                    retVal.Load(cmd.ExecuteReader());
                }
            }
            return(retVal);
        }