コード例 #1
0
        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);
        }
コード例 #2
0
        protected bool execDeleteA(string query)
        {
            ResultExec rs = execute(query, System.Data.CommandType.Text);

            if (rs.resultNumber > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public int XoaTN(string MaQHGD)
        {
            ResultExec result = execute("delete QUAN_HE_GIA_DINH where MAQHGD=" + MaQHGD, System.Data.CommandType.Text);

            return(result.resultNumber);
        }