예제 #1
0
        static void Main()
        {
            Database db = new Database ("carlosble.dyndns.org", "mono", "5432", "conflux", "");
            db.Connect();
            db.ExecuteQuery("SELECT * FROM users");
            DataSet dataset = db.ActiveDataSet();
            foreach (DataRow fila in dataset.Tables[0].Rows)
            {
                int id = (int) fila[0];
                string user_name = (string) fila[2];
                string password = (string) fila[3];
             		Console.WriteLine("Nombre: {0},{1},{2}\n", id, user_name, password);

            }

            // Tirando de las interfaces IDb, me vale para cualquier base de datos porque todos los
            // conectores implementan estas interfaces:
            IDbConnection conn = db.connection;
            IDbCommand comm = conn.CreateCommand();
            IDbCommand comm2 = conn.CreateCommand();
            IDbTransaction trans = conn.BeginTransaction();

            comm.CommandText = "Insert into users values (3,3,'xxx','xxx',true)";
            comm.ExecuteNonQuery();  // ¿ en que se diferencia esto
            comm.CommandText = "Insert into users values (4,4,'yyy','yyy',true)";
            comm.ExecuteReader();   //    de esto otro ?
            comm.CommandText = "Insert into users values (5,5,'yyy','yyy',true)";
            comm.ExecuteReader();
            comm.Transaction = trans;
            //trans.Commit();

            IDbTransaction trans2 = conn.BeginTransaction();
            //comm.CommandText = "Insert into users values (6,6,'aaa','aaa',true)";
            //comm.Transaction = trans2;
            //trans2.Commit();
        }
        ////////////////////////////////////////////////////////////////////////////////
        ///<summary>
        ///Class constructor. 
        ///</summary>
        ///<param name="dbServer">Database server name or ip address</param>
        ///<param name="dbName">Database name</param>
        ///<param name="dbPort">Database connection port</param>
        ///<param name="dbUser">Database owner</param>
        ///<param name="dbPass">Database owner password</param>
        public GenericDatabase(string dbServer, string dbName, string dbPort, 
							 			string dbUser, string dbPass)
        {
            try
            {
                db = new Database(dbServer, dbName, dbPort, dbUser, dbPass);
            }
            catch (Exception e)
            {
                Exception wrappedEx = new Exception(
                    ErrorManager.AddLayer(e, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
        }