Monday, January 23, 2006

Google Map Dynamic Data Generated from SQL Database C# .Net Codebehind

Definition of MapDataAccess class with method GetGeoCodesCountry:

public class MapDataAccess
{
private SqlConnection conn;

public MapDataAccess()
{
this.conn = new SqlConnection(Global.CMCONNSTRING);
}

public SqlDataReader GetGeoCodesCountry(string strCountry)
{

string queryString="SELECT *";
queryString += " FROM People where ADR1_COUNTRY='" + strCountry + "' order by lname";

return SqlHelper.ExecuteReader(conn, CommandType.Text, queryString);

}
}

Code behind codes that returns Google Map data xml file. You could pass back Session["CountryCode"] by set up a postback event on dropdownlist from client:

private void Page_Load(object sender, System.EventArgs e)
{
MapDataAccess da = new MapDataAccess();
SqlDataReader dr;
string strCountry = Session["CountryCode"].ToString();
dr = da.GetGeoCodesCountry(strCountry);

Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8);
objX.WriteStartElement("markers");

while(dr.Read())
{
if ((dr["LATTITUDE"].ToString() != "")&&(dr["LONGITUDE"].ToString()!=""))
{
objX.WriteStartElement("marker");
objX.WriteAttributeString("lat", dr["LATTITUDE"].ToString());
objX.WriteAttributeString("lng",dr["LONGITUDE"].ToString());
objX.WriteEndElement();
}
}
da.closeConn();

objX.WriteEndElement();
objX.Flush();
objX.Close();
Response.End();
}

Note: These are not complete list of my original codes, please make necessary changes according to your situation.

2 Comments:

Blogger James Baker said...

Hello Friend! I just came across your blog and wanted to
drop you a note telling you how impressed I was with
the information you have posted here.
Keep up the great work, you are providing a great resource on the Internet here!
If you have a moment, please make a visit to my affordable web hosting services site.
Good luck in your endeavors!

7:05 PM  
Blogger All Pro Color said...

Find the most powerful and user friendly online publishing and printing service available! Innovative publishing editor and superior commercial printing let you control, create and manage your business image and brand.

5:43 PM  

Post a Comment

<< Home