using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Text; namespace TimedUpload.utils { public class MySqlHelper { private readonly string connStr; public MySqlHelper(string configConnStrKey) { connStr = ConfigurationManager.AppSettings[configConnStrKey]; } public DataTable GetDataTable(string sql) { MySqlCommand cmd; MySqlConnection con = new MySqlConnection(connStr); MySqlDataAdapter msa; try { con.Open(); cmd = new MySqlCommand(sql, con); msa = new MySqlDataAdapter(cmd); DataTable dt = new DataTable(); msa.Fill(dt); con.Close(); return dt; } catch (Exception ex) { con.Close(); return null; } } public int ExecuteNonQuery(string sql) { MySqlCommand cmd; MySqlConnection con = new MySqlConnection(connStr); try { con.Open(); cmd = new MySqlCommand(sql, con); int rs = cmd.ExecuteNonQuery(); con.Close(); return rs; } catch (Exception ex) { con.Close(); return 0; } } } }