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)); }
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(); } } }
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); }