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