/// <summary> /// get an instance of object /// </summary> /// <param name="myID"></param> public s_hazmat getObjects_hazmat(System.Int32 myID) { s_hazmat mys_hazmat = new s_hazmat(); CnxBase myBase = new CnxBase(); string reqSQL = "SELECT id_especialidad,id_sector,prioridad,contacto,id_central FROM s_hazmat WHERE (id_especialidad=" + myID + ")"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); NpgsqlDataReader myReader = myCommand.ExecuteReader(); if (myReader.Read()) { mys_hazmat.id_especialidad = Convert.ToInt32(myReader[0]); mys_hazmat.id_sector = Convert.ToInt32(myReader[1]); mys_hazmat.prioridad = Convert.ToInt32(myReader[2]); mys_hazmat.contacto = myReader[3].ToString(); mys_hazmat.id_central = Convert.ToInt32(myReader[4]); } myBase.CloseConnection(myConn); } catch (Exception myErr) { throw(new Exception(myErr.ToString() + reqSQL)); } return(mys_hazmat); }
/// <summary> /// modify a record /// </summary> public void modifys_hazmat(s_hazmat mys_hazmat) { CnxBase myBase = new CnxBase(); string reqSQL = "UPDATE s_hazmat SET id_especialidad=" + mys_hazmat.id_especialidad + ",id_sector=" + mys_hazmat.id_sector + ",prioridad=" + mys_hazmat.prioridad + ",contacto='" + mys_hazmat.contacto + "',id_central=" + mys_hazmat.id_central + " WHERE (id_especialidad=" + mys_hazmat.id_especialidad + ")"; 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> /// add a record /// </summary> /// <param name="myID"></param> public void adds_hazmat(s_hazmat mys_hazmat) { CnxBase myBase = new CnxBase(); string reqSQL = "INSERT INTO s_hazmat (id_especialidad,id_sector,prioridad,contacto,id_central) VALUES (" + mys_hazmat.id_especialidad + "," + mys_hazmat.id_sector + "," + mys_hazmat.prioridad + ",'" + mys_hazmat.contacto + "'," + mys_hazmat.id_central + ")"; 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)); } }