/// <summary> /// add a record /// </summary> /// <param name="myID"></param> public void Insert(dh_categorias mydh_cat) { CnxBase myBase = new CnxBase(); string reqSQL = "INSERT INTO dh_categorias (categoria) VALUES ('" + mydh_cat.categoria + "')"; 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(dh_categorias mydh_cat) { CnxBase myBase = new CnxBase(); string reqSQL = "UPDATE dh_categorias SET id_categoria=" + mydh_cat.id_categoria + ",categoria='" + mydh_cat.categoria + "' WHERE (id_categoria=" + mydh_cat.id_categoria + ")"; 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> /// get an instance of object /// </summary> /// <param name="myID"></param> public dh_categorias getObject(System.Int32 myID) { dh_categorias dh_cat = new dh_categorias(); CnxBase myBase = new CnxBase(); string reqSQL = "SELECT id_categoria,categoria FROM dh_categorias WHERE (id_categoria=" + myID + ")"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); NpgsqlDataReader myReader = myCommand.ExecuteReader(); if (myReader.Read()) { dh_cat.id_categoria = Convert.ToInt32(myReader[0]); dh_cat.categoria = myReader[1].ToString(); } myBase.CloseConnection(myConn); } catch (Exception myErr) { throw (new Exception(myErr.ToString() + reqSQL)); } return(dh_cat); }