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