protected ResultExec execute(string query, CommandType type, params SqlParameter[] param) { ResultExec rs = new ResultExec(); OpenConnection(); try { SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = type; if (type == CommandType.StoredProcedure) { cmd.Parameters.AddRange(param); } rs.resultNumber = cmd.ExecuteNonQuery(); rs.resultText = rs.resultNumber + " row(s) affected"; cmd.Dispose(); } catch (Exception ex) { rs.resultText = "Lỗi: " + ex.Message; } con.Close(); return(rs); }
protected bool execDeleteA(string query) { ResultExec rs = execute(query, System.Data.CommandType.Text); if (rs.resultNumber > 0) { return(true); } return(false); }
protected void execUpdate(string query, T entity, CommandType type = CommandType.Text, params SqlParameter[] param) { lblMessage.Text = "...Processing..."; ResultExec rs = execute(query, type, param); if (rs.resultNumber > 0) { UpdateRow(entity); } lblMessage.Text = rs.resultText; }
protected void execDelete(string query, CommandType type = CommandType.Text, params SqlParameter[] param) { lblMessage.Text = "...Processing..."; ResultExec rs = execute(query, type, param); if (rs.resultNumber > 0) { DeleteRow(); } lblMessage.Text = rs.resultText; cellclick(dtGrid.CurrentRow); }
protected void execInsert(string query, T entity, CommandType type = CommandType.Text, params SqlParameter[] param) { lblMessage.Text = "...Processing..."; ResultExec rs = execute(query, type, param); if (rs.resultNumber > 0) { InsertNewRow(entity); rs.resultText = "Insert Successfully"; } lblMessage.Text = rs.resultText; }
protected int execInsert(string query, params SqlParameter[] param) { lblMessage.Text = "...Processing..."; ResultExec rs = executeReturnValue(query, param); if (rs.resultNumber > 0) { lblMessage.Text = "Insert Successfully"; return(rs.resultNumber); } lblMessage.Text = rs.resultText; return(-1); }
private ResultExec executeReturnValue(string query, params SqlParameter[] param) { ResultExec rs = new ResultExec(); OpenConnection(); try { SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddRange(param); rs.resultNumber = int.Parse(cmd.ExecuteScalar().ToString()); rs.resultText = rs.resultNumber + " row(s) affected"; cmd.Dispose(); } catch (Exception ex) { rs.resultText = "Lỗi: " + ex.Message; } con.Close(); return(rs); }
public int XoaTN(string MaQHGD) { ResultExec result = execute("delete QUAN_HE_GIA_DINH where MAQHGD=" + MaQHGD, System.Data.CommandType.Text); return(result.resultNumber); }