MapPoint 2006, SQL Server 2005 and C#

devnait
03-20-2008, 11:16 AM
Hello all,

I just joined this community and hope you guys can help me. I started with MapPoint development two days ago and can't work it out.
We use an SQL Server 2005 database with columns containing the zip code of the city in Germany and another with the profite for each of them. Now I am trying to write a C# program which should get the data from the database and then represent it using the MapPoint Winform.
At this point I got all the needed values from the database but can't figure out how I could display them. I guess their format is wrong since it is not a dataset.

I hope someone can help me with this.
Thanks in advance

Eric Frost
03-20-2008, 11:53 AM
Do you want to post a snippet showing how far you have gotten with the code so far?

How are you connecting to SQL?

Eric

devnait
03-28-2008, 03:37 AM
Hello all,

my code is not very sophisticated I simply wrote a .net App and used the System.Data.SqlClient Namespace to save the query results as a string. This looks something like this:

string status;
SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=TEST;Integrated Security=SSPI; Asynchronous Processing=true");

string myQuery = "select postcode, contactid,lastname from customers";
SqlCommand command = new SqlCommand(myQuery, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
int counter = 0;
int[] ids = new int[100];
hashUmsatz.Clear();
hashPlz.Clear();
this.StatusLabel.Visible = true;
try
{
while (reader.Read() && counter < 100)
{
try
{
status = "Processing Postcodes: " + reader.GetString(0) + ", " + reader.GetInt32(1) + ", " + reader.GetString(2);
this.StatusLabel.Text = status;
this.StatusLabel.Refresh();
hashPlz.Add(reader.GetInt32(1), reader.GetString(0));
hashUmsatz.Add(reader.GetInt32(1), reader.GetString(2));
ids[counter] = reader.GetInt32(1);

}
catch (Exception)
{
Console.WriteLine("Datensatz fehlerhaft");
}
counter++;
}
}
finally
{
reader.Close();
connection.Close();

}


I got the feeling that it is not possible to map my data, i got from the database and saved as a string, onto the MapPoint map.
Furthermore, another question came up: We want to include this feature into an exsiting product. Is it possible to use the application and the features without MapPoint installed?

Best regards,
Sebastian

Eric Frost
03-28-2008, 04:46 AM
I'm not great with C++, and I'm not sure actually what a hash is.. is it like an array? but if you have the Postcode in a string, you can map it.. :bulb2: take a look at the examples MapPoint help file. Start with the FindResults method.

MapPoint *does* need to be installed.. there is an ActiveX control, but it still needs to be installed.

Eric

devnait
03-28-2008, 04:56 AM
Hello Eric,

thanks for the fast reply. Actually the code should be C# and I am not very good at that ;-)
I was trying to use a hash function to have a fast access to my data that I extracted from the SQL Database. Furthermore, the Hash table is dynamic. I got a unique customer number, the postcode and some fictional data about the sales. How would you organise this? Simply in a string or an array? I used an array so far and wanted to use the unique customer numbers as index...this didn't work out so well.

Thank you very much for the help so far :-)

Best regards,
Sebastian

Eric Frost
03-28-2008, 05:19 AM
Oh, I'm sorry, that is C#. And it says so in your subject line :1eye:

I don't have a suggestion about the hash or string or array, etc. but I'd recommend to try to get the simplest example or code snippet from the MapPoint help file working and then work backwards from there.

Eric

devnait
04-01-2008, 02:22 AM
Hello again,

thanks to Eric I can successfully find locations on the map, but I am not sure how I can attach data to these locations. I read the numbers from a SQL database and got them saved within my source code.
Another question I got is if it is possible to zoom in on a specific country. I now see Europe and I am just interested in Germany.

Thanks in advance
Sebastian

Wilfried
04-02-2008, 03:48 AM
Hi,

ActiveMap has a Location property and that is the Location of the center of the screen. You can save latitude, longitude, altitude of it and set it again at startup of your application.

devnait
04-03-2008, 05:12 PM
Thanks Wilfried, I'll check that out first thing tomorrow.
I tried further to get my data into a MapPoint.Dataset. I implemented the Dataset interface but i am not sure how to write the needed methods. I am getting the feeling that I missed something very big to do this. Furthermore, I had problems using the displaydatamap method because i didn't have all the parameters and didn't know what the are standing for.

I hope someone can help. Thanks everyone so far.
Regards
Sebastian

Eric Frost
04-03-2008, 05:29 PM
I don't expect that what you want to do is that hard, do you have the option to hire or contract with some person to do it for you or write sample code for your specific situation? You can read the data into code, you can render your data, what is missing exactly?

OTOH, the DisplayDataMap method *is* tricky.. personally, I have frequently referenced the book "Programming MapPoint in .NET" and the examples in there when I've had problems with the DisplayDataMap method... which seems to be every time I try to use it! :stupid2:

devnait
04-04-2008, 01:28 AM
Hello Eric,

my problem is that i cannot render my data completely. I can find places using the zipcode/postcode but i cannot map the data I got for the location. So i don't get diagrams and stuff to represent my profits which i got the same way as the postcodes. So I accutally just need to make it visible on the map.

Best regards,
Sebastian

 
Web mp2kmag.com
mapforums.com