/// <summary> /// get an instance of object /// </summary> /// <param name="myID"></param> public p_policia getObjectp_policia(System.Int32 myID) { p_policia myp_policia = new p_policia(); CnxBase myBase = new CnxBase(); string reqSQL = "SELECT gid,sgc1,sgc2,geom FROM p_policia WHERE (gid=" + myID + ")"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); NpgsqlDataReader myReader = myCommand.ExecuteReader(); if (myReader.Read()) { myp_policia.gid = Convert.ToInt32(myReader[0]); myp_policia.sgc1 = Convert.ToInt64(myReader[1]); myp_policia.sgc2 = myReader[2].ToString(); myp_policia.the_geom = myReader[3].ToString(); } myBase.CloseConnection(myConn); } catch (Exception myErr) { throw(new Exception(myErr.ToString() + reqSQL)); } return(myp_policia); }
/// <summary> /// modify a record /// </summary> public void Update(p_policia myp_policia) { CnxBase myBase = new CnxBase(); string reqSQL = "UPDATE p_policia SET gid=" + myp_policia.gid + ",sgc1=" + myp_policia.sgc1 + ",sgc2='" + myp_policia.sgc2 + "',geom='" + myp_policia.the_geom + "' WHERE (gid=" + myp_policia.gid + ")"; 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 Insert(p_policia myp_policia) { CnxBase myBase = new CnxBase(); string reqSQL = "INSERT INTO p_policia (gid,sgc1,sgc2,geom) VALUES (" + myp_policia.gid + "," + myp_policia.sgc1 + ",'" + myp_policia.sgc2 + "','" + myp_policia.the_geom + "')"; 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)); } }