Example #1
0
        // トランザクション用
        public static void UpdateTran(string sql, SQLSERVER DB, string[] outputCol = null)
        {
            string difference = "";

            #region OUTPUT句のSQL生成
            if (outputCol == null)
            {
                var outputSql = " OUTPUT ";
                foreach (string item in outputCol)
                {
                    outputSql = outputSql + " '" + item + " 「 ' + inserted." + item + " + ' 」 => 「 ' + deleted." + item + " + ' 」  ' +";
                }
                outputSql = outputSql.TrimEnd('+');
                sql       = sql.Insert(sql.IndexOf("WHERE"), outputSql);
            }
            #endregion
            try
            {
                difference = DB.ExecuteScalar(sql);
                SQLSERVERHelper.Log("0", "", "更新", sql, difference);
            }
            catch (Exception)
            {
                //SQLSERVERHelper.Log("1", ex.Message + Environment.NewLine + ex.StackTrace, errorTitle, sql, "NoLoginUser", difference);
                //MessageBox.Show("エラー発生:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
                throw;
            }
        }
Example #2
0
        public static void Insert(string sql, string connection)
        {
            SQLSERVER DB = new SQLSERVER(connection);

            try
            {
                DB.Open();
                DB.ExecuteNonQuery(sql);
                SQLSERVERHelper.Log("0", "", "挿入", sql);
            }
            catch (Exception)
            {
                //SQLSERVERHelper.Log("1", ex.Message + Environment.NewLine + ex.StackTrace, errorTitle, sql, "NoLoginUser");
                //MessageBox.Show("エラー発生:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
                throw;
            }
            finally
            {
                DB.Close();
            }
        }