c# - adding several elements via foreach loop -


i trying parse array of double numbers instead of static string did here test, enter number in textbox , after clicking button pick relevant coordinates database. need parse many pairs of coordinates (lat,lon) tried foreach loop couldn't figure out @ 3rd last line. name of field in databse longitude , latitude.

new xelement(n + "linestring", new xelement(n + "coordinates", lat+","+lon)))))); 

code:

protected void page_load(object sender, eventargs e)     {         //string[] values = {"12.1", "2.1","3.1","2.1" };         string values = "12.1,2.1,3.1,1.1";         string[] latlon = values.split(',');          sqlconnection sqlcon = new sqlconnection(constr);         // string com = "select latitude, longitude coordinates imei=@txtimei";         sqlcommand sqlcom = new sqlcommand("getlatlon", sqlcon);         sqlcom.commandtype = commandtype.storedprocedure;         sqlcom.parameters.add("@imei", sqldbtype.varchar).value = textbox1.text;          datatable dt = new datatable();         sqldataadapter sda = new sqldataadapter(sqlcom);         sda.fill(dt);          try         {             sqlcon.open();             sqlcom.executenonquery();                   double lon = double.parse(latlon[0]);                 double lat = double.parse(latlon[1]);                 response.write(lon + "," + lat);                  xnamespace n = "http://earth.google.com/kml/2.2";                 response.write("kml generated");                 new xelement(n + "kml");//just n+ each underlying elements                 //  xnamespace n = "http://earth.google.com/kml/2.2";                 xdocument doc = new xdocument(                 new xdeclaration("1.0", "utf-8", ""),                 new xcomment("this comment me"),                 new xelement(n + "kml",                 new xelement(n + "document",                         new xelement(n + "name", "something"), new xelement(n + "placemark",                         new xattribute("id", "1"),                         new xelement(n + "title", "something"),                         new xelement(n + "description", "something"),                         new xelement(n + "lookat",                         new xelement(n + "longitude", "12.1"),                         new xelement(n + "latitude", "2.1")),                         new xelement(n + "linestring", new xelement(n + "coordinates", lat+","+lon))))));                         doc.save(server.mappath(@"~\marker5.kml"));                         response.write("kml generated");            }         catch (exception exc)         {             response.write(exc.message);         }                 {             sqlcon.close();         }     }      } 


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -