public void Insert(string query) { using (var db = new xConnection()) { db.Connection.Open(); using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; cmd.ExecuteNonQuery(); } } }
public async void InsertAsync(string query) { using (var db = new xConnection()) { await db.Connection.OpenAsync(); using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; await cmd.ExecuteNonQueryAsync(); } } }
public async Task <DataTable> QueryAsync(string query, bool isQuery = true) { using (var db = new xConnection()) { await db.Connection.OpenAsync(); if (isQuery) { using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; try { using (DbDataReader dr = await cmd.ExecuteReaderAsync()) { if (dr.HasRows) { DataTable dt = new DataTable(); dt.Load(dr); return(dt); } } return(null); } catch (MySqlException e) { Log.Error("MYSQL Error query:" + e.ToString()); return(null); } } } else { try { using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; await cmd.ExecuteNonQueryAsync(); } return(null); } catch (MySqlException e) { Log.Error("MYSQL Error:" + e.ToString()); return(null); } } } }
public DataTable Query(string query, bool isQuery = true) { using (var db = new xConnection()) { db.Connection.Open(); if (isQuery) { DataTable dt = new DataTable(); using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; try { using (DbDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { dt.Load(dr); return(dt); } dr.Close(); } return(null); } catch (MySqlException e) { Log.Error("MYSQL Error select:" + e.ToString()); return(null); } } } else { try { using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; cmd.ExecuteNonQuery(); } } catch (MySqlException e) { Log.Error("MYSQL Error:" + e.ToString()); } return(null); } } }
public void Open() { try { using (var db = new xConnection()) { db.Connection.Open(); Log.Info("Connection Open ! "); } } catch (Exception ex) { Log.Info("Can not open connection ! "); } }
public void Update(string query) { Task.Run(() => { using (var db = new xConnection()) { db.Connection.Open(); using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; cmd.ExecuteNonQuery(); } } }); }
public async Task <DataTable> MultipleQueryAsync(string query, string nametable, bool isQuery = true) { using (var db = new xConnection()) { await db.Connection.OpenAsync(); if (isQuery) { using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; try { using (MySqlDataAdapter data = new MySqlDataAdapter(cmd)) { DataSet ds = new DataSet(); data.Fill(ds, nametable); DataTable dt = ds.Tables[nametable]; return(dt); } return(null); } catch (MySqlException e) { Log.Error("MYSQL Error select:" + e.ToString()); return(null); } } } else { try { using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @query; await cmd.ExecuteNonQueryAsync(); } } catch (MySqlException e) { Log.Error("MYSQL Error:" + e.ToString()); } return(null); } } }