Ejemplo n.º 1
0
        public HowTo_UseTransactions()
        {
//<document>
            long _iduser = 0L;

            OGen.lib.datalayer.DBConnection _con
                = OGen.lib.datalayer.DBConnectionsupport.CreateInstance(
                      // set your db server type here
                      OGen.lib.datalayer.DBServerTypes.PostgreSQL,
                      // and connectionstring
                      "Server=127.0.0.1;Port=5432;User ID=postgres;Password=passpub;Database=OGen-NTier_UTs;"
                      );

// before beginning a transaction we need to open the connection
            _con.Open();
            try {
                // beginning transaction
                _con.Transaction.Begin();

                // performing some operations on db
                _con.Execute_SQLQuery(
                    string.Format(
                        "delete from \"User\" where \"IDUser\" = {0}",
                        _iduser.ToString()
                        )
                    );

                // commit transaction
                _con.Transaction.Commit();
            } catch (Exception _ex) {
                // rollback transaction
                _con.Transaction.Rollback();
            } finally {
                // terminate transaction
                _con.Transaction.Terminate();
            }
// closing connection
            _con.Close();
            _con.Dispose(); _con = null;
//</document>
        }
Ejemplo n.º 2
0
        public HowTo_Execute_SQLQuery()
        {
//<document>
            long _iduser = 0L;

            OGen.lib.datalayer.DBConnection _con
                = OGen.lib.datalayer.DBConnectionsupport.CreateInstance(
                      // set your db server type here
                      OGen.lib.datalayer.DBServerTypes.PostgreSQL,
                      // and connectionstring
                      "Server=127.0.0.1;Port=5432;User ID=postgres;Password=passpub;Database=OGen-NTier_UTs;"
                      );

// executing your sql query
            _con.Execute_SQLQuery(
                string.Format(
                    "delete from \"User\" where \"IDUser\" = {0}",
                    _iduser.ToString()
                    )
                );

            _con.Dispose(); _con = null;
//</document>
        }