Bonjour ,

J'ai besoin de crée une map et d'afficher les positions a partir de la base de donner

J'ai trouvé ce tutoriel http://deepak-sharma.net/2013/02/08/...g-asp-dot-net/

Et j'ai procédé aux étapes expliquées , Lorsque j’exécute ce code j'obtient l'erreur suivante :
NullReferenceExeption La référence d'objet n'est pas définie à une instance d'un objet
a la ligne suivante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString))
Quelqu'un peut m'expliquer pourquoi? et elle est ou l'erreur

C'est très gentil Merci Beaucoup


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Locations = GetLocations();
        Literal1.Text = @"
          <script type='text/javascript' src='http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0'>
          </script>
          <script type='text/javascript'>
               var  map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
                          credentials: 'Atu0aMfGjfMho8ryXcT8G0YGVXuRmAyglkIvBOKTzt3WP9qLi0txukM-6VYRUzfw'
               });
 
               function GetMap() {
                    map.entities.clear();
                    " + Locations + @"
 
                    function ZoomIn(e){
                         if (e.targetType == 'pushpin'){
                               var location = e.target.getLocation();
                               map.setView({
                                    zoom:5,
                                    center: location
                               });
                   }
              }
       }
</script>";
    }
    private string GetLocations()
    {
        string Locations = "";
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("SELECT Altitude, longtitute FROM Bus ORDER BY BusId DESC LIMIT 1", con);
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Locations += "var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(" +
                    reader["Latitude"].ToString() + ", " + reader["Longitude"].ToString() +
                    "), null);Microsoft.Maps.Events.addHandler(pushpin, 'mouseup', ZoomIn);map.entities.push(pushpin);";
            }
        }
        return Locations;
    }
}