예제 #1
0
        private void InsertSql(string sql)
        {
            dtResult = null;
            try
            {
                using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                {
                    conn.Open();
                    PDBCommand   cmd    = conn.CreateCommand();
                    PDBErrorCode retVal = cmd.ExecuteInsert(sql);
                    if (retVal != PDBErrorCode.PdbE_OK)
                    {
                        this.richTxtMsg.Text      = "SQL:\n" + sql + "\n发生错误:\n";
                        this.richTxtMsg.Text     += PDBErrorMsg.GetErrorMsg(retVal);
                        this.richTxtMsg.ForeColor = Color.Red;
                    }
                    else
                    {
                        this.richTxtMsg.Text      = "SQL:\n" + sql + "\n执行成功!";
                        this.richTxtMsg.ForeColor = Color.Green;
                    }
                }
            }
            catch (Exception ex)
            {
                this.richTxtMsg.Text      = "执行SQL:\n" + sql + "\n发生错误:" + ex.Message;
                this.richTxtMsg.ForeColor = Color.Red;
            }

            this.tabControlResult.SelectedTab = this.tabPageMsg;
            BindResult();
        }
예제 #2
0
        /// <summary>
        /// Execue sql Command
        /// </summary>
        /// <param name="Command">SQL command String</param>
        /// <param name="Timeout">[option] timeout of database connect(seconds)</param>
        /// <returns>
        /// The number of rows affected
        /// </returns>
        public Int32 ExecueCommand(String Command, Int32 Timeout = 30)
        {
            Int32 Value = 0;

            if (conn == null)
            {
                throw new Exception("Connection has not initialize.");
            }

            if (conn.IsValid() != true)
            {
                throw new Exception("Connection has not opened.");
            }

            PDBCommand cmd = conn.CreateCommand();

            cmd.ExecuteInsert(Command);

            return(cmd.SuccessCount);
        }