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(); } } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }