public static int ExecuteNonQuery(string sql, SqlTransaction Tran) { SqlConnection con = Tran.Connection; ConnectionState cs = con.State; SqlCommand cmd = new SqlCommand(sql, con); cmd.Transaction = Tran; int i; try { if (cs != ConnectionState.Open) { con.Open(); } i = cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException ex) { ErrLogRecorder.SqlError(ex, sql); throw; } finally { cmd.Dispose(); if (cs == ConnectionState.Closed) { con.Close(); } } return(i); }
public static object ExecuteScalar(string sql, SqlConnection con) { ConnectionState cs = con.State; SqlCommand cmd = new SqlCommand(sql, con); try { if (cs != ConnectionState.Open) { con.Open(); } return(cmd.ExecuteScalar()); } catch (System.Data.SqlClient.SqlException ex) { ErrLogRecorder.SqlError(ex, sql); throw; } finally { cmd.Dispose(); if (cs == ConnectionState.Closed) { con.Close(); } } }
public static object ExecuteScalar(string sql, SqlTransaction tran) { SqlCommand cmd = new SqlCommand(sql, tran.Connection, tran); try { return(cmd.ExecuteScalar()); } catch (System.Data.SqlClient.SqlException ex) { ErrLogRecorder.SqlError(ex, sql); throw; } finally { cmd.Dispose(); } }
public static DataTable GetDataTable(string sql) { //SqlConnection con = GetSqlCon(); string ConStr = ConfigurationManager.ConnectionStrings[SQLConnString].ConnectionString; SqlDataAdapter da = new SqlDataAdapter(sql, ConStr); DataTable dt = new DataTable(); try { da.Fill(dt); } catch (System.Data.SqlClient.SqlException ex) { dt.Dispose(); ErrLogRecorder.SqlError(ex, sql); throw; } finally { da.Dispose(); } return(dt); }
public static DataSet GetDataSet(string sql, SqlConnection con) { DataSet ds = new DataSet(); SqlDataAdapter Da = new SqlDataAdapter(sql, con); try { Da.Fill(ds); } catch (System.Data.SqlClient.SqlException ex) { ds.Dispose(); Da.Dispose(); ErrLogRecorder.SqlError(ex, sql); throw ex; } Da.Dispose(); return(ds); }
public static object ExecuteScalar(string sql) { SqlConnection con = GetSqlCon(true); SqlCommand cmd = new SqlCommand(sql, con); try { return(cmd.ExecuteScalar()); } catch (System.Data.SqlClient.SqlException ex) { ErrLogRecorder.SqlError(ex, sql); throw; } finally { cmd.Dispose(); con.Close(); con.Dispose(); } }
public static DataTable GetDataTable(string sql, SqlConnection con) { DataTable dt = new DataTable(); SqlDataAdapter Da = new SqlDataAdapter(sql, con); try { Da.Fill(dt); } catch (System.Data.SqlClient.SqlException ex) { dt.Dispose(); ErrLogRecorder.SqlError(ex, sql); throw; } finally { Da.Dispose(); } return(dt); }
public static int ExecuteNonQuery(string sql) { SqlConnection con = GetSqlCon(true); SqlCommand cmd = new SqlCommand(sql, con); int i; try { i = cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException ex) { ErrLogRecorder.SqlError(ex, sql); throw; } finally { cmd.Dispose(); con.Close(); con.Dispose(); } return(i); }