public int ExecuteScalar(string strSQL, params SqlParameter[] Parameters) { int temp = 0; DBAccess myBase = new DBAccess(); try { SqlConnection myConn = myBase.OpenConnection(connectionString); SqlCommand myCommand = new SqlCommand(strSQL, myConn); myCommand.Parameters.Clear(); foreach (SqlParameter par in Parameters) { myCommand.Parameters.Add(par); } temp = Convert.ToInt32(myCommand.ExecuteScalar().ToString()); myCommand.Dispose(); myBase.CloseConnection(myConn); return(temp); } catch (Exception myException) { throw (new Exception(myException.Message + " => " + strSQL)); } }
public SqlDataReader getReader(SqlCommand cmd) { DBAccess myBase = new DBAccess(); try { SqlConnection myConn = myBase.OpenConnection(connectionString); cmd.Connection = myConn; SqlDataReader reader = cmd.ExecuteReader(); //myBase.CloseConnection(myConn); return(reader); } catch (Exception myException) { throw (new Exception(myException.Message + " => " + cmd.CommandText)); } }
public void ExecuteSQL(SqlCommand mCommand) { DBAccess myBase = new DBAccess(); try { SqlConnection myConn = myBase.OpenConnection(connectionString); mCommand.Connection = myConn; mCommand.ExecuteNonQuery(); mCommand.Dispose(); myBase.CloseConnection(myConn); } catch (Exception myException) { throw (new Exception(myException.Message + " => " + mCommand.CommandText)); } }
public int ExecuteScalar(SqlCommand mCommand) { int temp = 0; DBAccess myBase = new DBAccess(); try { SqlConnection myConn = myBase.OpenConnection(connectionString); mCommand.Connection = myConn; temp = Convert.ToInt32(mCommand.ExecuteScalar().ToString()); mCommand.Dispose(); myBase.CloseConnection(myConn); return(temp); } catch (Exception myException) { throw (new Exception(myException.Message + " => " + mCommand.CommandText)); } }
public DataSet getDataSet(SqlCommand mCommand) { DBAccess myBase = new DBAccess(); try { SqlConnection myConn = myBase.OpenConnection(connectionString); mCommand.Connection = myConn; SqlDataAdapter myDataAdapter = new SqlDataAdapter(mCommand); DataSet myDataSet = new DataSet(); myDataAdapter.Fill(myDataSet); myBase.CloseConnection(myConn); return(myDataSet); } catch (Exception myException) { throw (new Exception(myException.Message + " => " + mCommand.CommandText)); } }
/// <summary> /// return a DataSet from SQL Request /// </summary> public DataSet getDataSet(string strSQL) { DBAccess myBase = new DBAccess(); try { SqlConnection myConn = myBase.OpenConnection(connectionString); SqlDataAdapter myDataAdapter = new SqlDataAdapter(strSQL, myConn); DataSet myDataSet = new DataSet(); myDataAdapter.Fill(myDataSet); myDataAdapter.Dispose(); myBase.CloseConnection(myConn); return(myDataSet); } catch (Exception myException) { throw (new Exception(myException.Message + " => " + strSQL)); } }
public void ExecuteSQL(string strSQL, params SqlParameter[] Parameters) { DBAccess myBase = new DBAccess(); try { SqlConnection myConn = myBase.OpenConnection(connectionString); SqlCommand myCommand = new SqlCommand(strSQL, myConn); myCommand.Parameters.Clear(); foreach (SqlParameter par in Parameters) { myCommand.Parameters.Add(par); } myCommand.ExecuteNonQuery(); myCommand.Dispose(); myBase.CloseConnection(myConn); } catch (Exception myException) { throw (new Exception(myException.Message + " => " + strSQL)); } }
public void ExecuteSQL(string strSQL) { DBAccess myBase = new DBAccess(); SqlConnection myConn = myBase.OpenConnection(connectionString); SqlTransaction tran = myConn.BeginTransaction(); try { SqlCommand myCommand = new SqlCommand(strSQL, myConn); myCommand.Transaction = tran; myCommand.ExecuteNonQuery(); tran.Commit(); myCommand.Dispose(); } catch (Exception myException) { tran.Rollback(); throw (new Exception(myException.Message + " => " + strSQL)); } finally { myBase.CloseConnection(myConn); } }
public DataSet getDataSet(string strSQL, SqlParameter[] Parameters) { DBAccess myBase = new DBAccess(); try { SqlConnection myConn = myBase.OpenConnection(connectionString); SqlCommand myCommand = new SqlCommand(strSQL, myConn); myCommand.Parameters.Clear(); foreach (SqlParameter par in Parameters) { myCommand.Parameters.Add(par); } SqlDataAdapter myDataAdapter = new SqlDataAdapter(myCommand); DataSet myDataSet = new DataSet(); myDataAdapter.Fill(myDataSet); myBase.CloseConnection(myConn); return(myDataSet); } catch (Exception myException) { throw (new Exception(myException.Message + " => " + strSQL)); } }