Exemplo n.º 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();
         }
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }