public static bool ExecuteNonQuery(SqlCommand cmd) { Conn fns = new Conn(); SqlConnection conn = fns.Connct(); try { cmd.Connection = conn; if (conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken) { conn.Open(); } cmd.ExecuteNonQuery(); cmd.Dispose(); return(true); } catch { return(false); } finally { conn.Close(); conn.Dispose(); } }
public static DataTable getTable(string sql) { DataTable dt = new DataTable(); Conn fns = new Conn(); SqlConnection conn = fns.Connct(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = sql; cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); da.Dispose(); cmd.Dispose(); } catch { } finally { conn.Close(); conn.Dispose(); } return(dt); }
public static DataTable getTable(SqlCommand cmd) { DataTable dt = new DataTable(); Conn fns = new Conn(); SqlConnection conn = fns.Connct(); try { cmd.Connection = conn; SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); da.Dispose(); cmd.Dispose(); } catch { } finally { conn.Close(); conn.Dispose(); } return(dt); }