public class Helper { private static string ConnString = ConfigurationManager.ConnectionStrings["app"].ConnectionString; public static SqlDataReader GetReader(string sql) { SqlConnection Conn = new SqlConnection(ConnString); Conn.Open(); SqlCommand comm = new SqlCommand(sql, Conn); SqlDataReader Reader = comm.ExecuteReader(CommandBehavior.CloseConnection); return Reader; } public static DataSet GetDataSet(string sql) { DataSet DataSet = new DataSet(); using (SqlConnection Conn = new SqlConnection(ConnString)) { Conn.Open(); SqlDataAdapter Adapter = new SqlDataAdapter(sql, ConnString); Adapter.Fill(DataSet); Conn.Close(); Conn.Dispose(); } return DataSet; } public static int ExecSql(string sql) { int i = 0; using (SqlConnection Conn = new SqlConnection(ConnString)) { Conn.Open(); SqlCommand comm = new SqlCommand(sql, Conn); i = comm.ExecuteNonQuery(); Conn.Close(); Conn.Dispose(); } return i; } }