/// <summary> /// get an instance of object /// </summary> /// <param name="myID"></param> public a_agenda_subcat getObjecta_agenda_subcat(System.Int32 myID) { a_agenda_subcat mya_agenda_subcat = new a_agenda_subcat(); CnxBase myBase = new CnxBase(); string reqSQL = "SELECT id_subcat,id_cat,nombre FROM a_agenda_subcat WHERE (id_subcat=" + myID + ")"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); NpgsqlDataReader myReader = myCommand.ExecuteReader(); if (myReader.Read()) { mya_agenda_subcat.id_subcat = Convert.ToInt32(myReader[0]); mya_agenda_subcat.id_cat = Convert.ToInt32(myReader[1]); mya_agenda_subcat.nombre = myReader[2].ToString(); } myBase.CloseConnection(myConn); } catch (Exception myErr) { throw(new Exception(myErr.ToString() + reqSQL)); } return(mya_agenda_subcat); }
/// <summary> /// add a record /// </summary> /// <param name="myID"></param> public void Insert(a_agenda_subcat mya_agenda_subcat) { CnxBase myBase = new CnxBase(); string reqSQL = "INSERT INTO a_agenda_subcat (id_cat,nombre) VALUES (" + mya_agenda_subcat.id_cat + ",'" + mya_agenda_subcat.nombre + "')"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); myCommand.ExecuteNonQuery(); myBase.CloseConnection(myConn); } catch (Exception myErr) { throw(new Exception(myErr.ToString() + reqSQL)); } }
/// <summary> /// modify a record /// </summary> public void Update(a_agenda_subcat mya_agenda_subcat) { CnxBase myBase = new CnxBase(); string reqSQL = "UPDATE a_agenda_subcat SET id_subcat=" + mya_agenda_subcat.id_subcat + ",id_cat=" + mya_agenda_subcat.id_cat + ",nombre='" + mya_agenda_subcat.nombre + "' WHERE (id_subcat=" + mya_agenda_subcat.id_subcat + ")"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); myCommand.ExecuteNonQuery(); myBase.CloseConnection(myConn); } catch (Exception myErr) { throw(new Exception(myErr.ToString() + reqSQL)); } }