예제 #1
0
 public static void ExecuteSqlTran(List <SQLInfo> SQLInfoList)
 {
     using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
     {
         conn.Open();
         SqlCommand cmd = new SqlCommand();
         cmd.Connection = conn;
         SqlTransaction tx = conn.BeginTransaction();
         cmd.Transaction = tx;
         try
         {
             foreach (SQLInfo sqlinfo in SQLInfoList)
             {
                 cmd.Parameters.Clear();
                 SqlHelper.PrepareCommand(cmd, conn, tx, sqlinfo.cmdType, sqlinfo.SQLStr, sqlinfo.parameters);
                 cmd.ExecuteNonQuery();
             }
             tx.Commit();
         }
         catch
         {
             tx.Rollback();
         }
     }
 }
예제 #2
0
        public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();

            SqlHelper.PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
            int val = cmd.ExecuteNonQuery();

            cmd.Parameters.Clear();
            return(val);
        }
예제 #3
0
        public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();

            SqlHelper.PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
            object val = cmd.ExecuteScalar();

            cmd.Parameters.Clear();
            return(val);
        }
예제 #4
0
        public static DataTable ExecuteDataTable(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();

            SqlHelper.PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable      dt = new DataTable();

            da.Fill(dt);
            cmd.Parameters.Clear();
            return(dt);
        }
예제 #5
0
        public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();

            SqlHelper.PrepareCommand(cmd, connection, null, commandType, commandText, commandParameters);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet        ds = new DataSet();

            da.Fill(ds);
            cmd.Parameters.Clear();
            return(ds);
        }
예제 #6
0
        public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();
            int        result;

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                SqlHelper.PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                conn.Close();
                conn.Dispose();
                result = val;
            }
            return(result);
        }
예제 #7
0
        public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand    cmd  = new SqlCommand();
            SqlConnection conn = new SqlConnection(connectionString);
            SqlDataReader result;

            try
            {
                SqlHelper.PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                result = rdr;
            }
            catch
            {
                conn.Close();
                throw;
            }
            return(result);
        }
예제 #8
0
        public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            SqlCommand cmd = new SqlCommand();
            int        val = 0;

            try
            {
                SqlHelper.PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
            }
            catch
            {
            }
            finally
            {
                connection.Close();
                connection.Dispose();
            }
            return(val);
        }