View Single Post

  #2 (permalink)  
Old 05-06-2008
black_fox_71 black_fox_71 is offline
Junior Member
White Belt
 
Join Date: Apr 2008
Posts: 11
Arrow Re: Probleme with access 2003 and MapPoint 2006

Hi,

I didn't found where was my problem. But, i changed my code, and it works now.

I have an other question now, the latest. There is one week, what i try to find how to use MapPoint 2006 and Access 2003 always in C#.

I have read the examples of Mappoint on the datasheet. But that dont works, moreover, there is any example on the web. And Even on your forum, when someone try to know how works access and mappoint there isn't any answer .

I give you a part of my code :

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
 
namespace Test_Map_point_access
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
#region variable pour la connection a la base de donnée
String objTemplate = "C:/Program Files/Microsoft MapPoint Europe/Templates/Nouvelle carte d'Europe.ptt";
MapPoint.Map objMap = null;
MapPoint.Symbols all;
//déclaration de la connection
privateOleDbConnection Conn = newOleDbConnection();
//déclaration du chemin de l'éxécutable
privatestring BDDPath = Application.ExecutablePath;
//déclaration du chemin de la connection de la base de donnée
privatestring ConnString;
#endregion
#region variables Connection pour ComboClass et listclass
//déclaration du dataset
privateDataSet DtsClass = newDataSet();
//déclaration de la datatable
privateDataTable DttClass = newDataTable();
//déclaration de la requete sql pour le comboclass
privatestring SqlClass = "SELECT * FROM Contacts";
#endregion
#region variables connection pour la datagrid et recherche
//déclaration du dataset
privateDataSet DtsGrid = newDataSet();
//déclaration du datatable
privateDataTable DttGrid = newDataTable();
//déclaration de la requete sql
privatestring SqlGrid = "SELECT * FROM Contacts";
//déclaration de la requete sql 
privatestring SqlSearch;
//déclaration du commande builder
privateOleDbCommandBuilder CmdGrid = newOleDbCommandBuilder();
//déclaration du datarow
privateDataRow DtrGrid;
#endregion
#region variables
//Import de la class Variable
ClassVariables CsV = newClassVariables();
#endregion
privatevoid Form1_Load(object sender, EventArgs e)
{
#region Construction de la connection
axMappointControl1.NewMap(objTemplate);
objMap = axMappointControl1.ActiveMap;
objMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleData;
 
//Arangement du chemin de la prise de la base de donnée
this.BDDPath = this.BDDPath.Substring(0, this.BDDPath.LastIndexOf("\\"));
//on crée le chemin de la connection a la base de donnée
this.ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + this.BDDPath + "\\Contacts.mdb";
//on crée la connection a la base de donnée
this.Conn.ConnectionString = this.ConnString;
#endregion
 
#region datagridview
//déclaration du data adapteur pour le datagridview
OleDbDataAdapter DtaGrid = newOleDbDataAdapter(this.SqlGrid, this.Conn);
//on leve l'exception
try
{
DtaGrid.Fill(this.DtsGrid, "Contacts");
}
catch (Exception ex)
{
//affichage de l'érreur
MessageBox.Show("Une Erreur est survenue, si cela persiste veuillez contacter au plus vite le programmeur");
//on ferme la connection
this.Conn.Close();
//on quitte l'application
Application.Exit();
}
//on rempli la liste avec le dataset 
this.DttGrid = this.DtsGrid.Tables["Contacts"];
//on affiche la liste dans le datagridview
this.Dtg.DataSource = this.DttGrid;
//on stylise la datagridview
this.StyleDtg();
#endregion
//rafraichissement de la fenetre
this.Show();
//on ferme la connection
this.Conn.Close();
}
 
 
#region Fonctions
privatevoid StyleDtg()
{
this.Dtg.ColumnHeadersDefaultCellStyle.Font = newFont("Tahoma", 9, FontStyle.Bold, GraphicsUnit.Point);
this.Dtg.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.ControlDark;
this.Dtg.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
this.Dtg.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
this.Dtg.DefaultCellStyle.Font = newFont("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Point);
this.Dtg.DefaultCellStyle.BackColor = Color.Empty;
this.Dtg.AlternatingRowsDefaultCellStyle.BackColor = SystemColors.ControlLight;
this.Dtg.CellBorderStyle = DataGridViewCellBorderStyle.Single;
this.Dtg.GridColor = SystemColors.ControlDarkDark;
Dtg.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
#endregion
privatevoid button_Afficher_rue_Click(object sender, EventArgs e)
{
//on vide le dataset 
this.DtsGrid.Clear ();
MapPoint.Field objField;


MapPoint.DataSets objDSS = axMappointControl1.ActiveMap.DataSets;
axMappointControl1.ActiveMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleTerrain;
//Base de données Access avec une table
//*******************************************
// zone de test de l'api mappoint avec access
//*******************************************
string szconn = "//Contacts.mdb";// The path must be change :D
object missing = System.Reflection.Missing.Value;
if (File.Exists("//Contacts.mdb") == true) // The path must be change too 
{
Console.WriteLine("Le fichier existe !");

object[] myranges = newobject[9] { 0, 4, 8, 12, 16, 20, 35, 50, 100 };
all = objMap.Symbols;
MapPoint.DataSet oDS = objDSS.ImportData(szconn, missing,
MapPoint.GeoCountry.geoCountryFrance,
MapPoint.GeoDelimiter.geoDelimiterTab,0);
//Define data map columns
object LatitudeIndex = 3;
object LongitudeIndex = 2;
object MoyenneIndex = 8;
//Now get fields
object[] datafields = newobject[3];
datafields[0] = oDS.Fields.get_Item(ref LongitudeIndex);
datafields[1] = oDS.Fields.get_Item(ref LatitudeIndex);
datafields[2] = oDS.Fields.get_Item(ref MoyenneIndex);

//affichage avec définition de l'échelle (couleur et intervalle)
MapPoint.DataMap datamap = oDS.DisplayDataMap(MapPoint.GeoDataMapType.geoDataMapTypeShadedCircle,
datafields, MapPoint.GeoShowDataBy.geoShowByLatLong,
MapPoint.GeoCombineDataBy.geoCombineByDefault,
MapPoint.GeoDataRangeType.geoRangeTypeDiscreteEqualRanges,
MapPoint.GeoDataRangeOrder.geoRangeOrderLowToHigh,
12, 8, myranges, missing, missing, missing, missing);
}
else
{
Console.WriteLine("Le fichier n'éxiste pas !");
}



//on vérifi qu'il y a quelque chose dans la txtsearch
this.SqlSearch = "SELECT * FROM Contacts Where Rue = 'Avenue Du 14 Juillet'";
//on ouvre la connection
this.Conn.Open ();
//déclaration du data adapter
OleDbDataAdapter Dta = newOleDbDataAdapter ( this.SqlSearch , this.Conn );
//on leve l'exception
try
{
//on rempli le dataset avec la table
Dta.Fill ( this.DtsGrid , "Contacts" );
}
catch ( Exception ex )
{
//affichage de l'érreur
MessageBox.Show ( "Une Erreur est survenue, si cela persiste veuillez contacter au plus vite le programmeur" );
//on ferme la connection
this.Conn.Close ();
//on ferme la fenetre
this.Close ();
//on quitte l'application
Application.Exit ();
}
//on rempli la liste du datagridview avec le dataset
this.DttGrid = this.DtsGrid.Tables [ "Contacts" ];
//on affiche la liste du datagridview dans le datagridview
this.Dtg.DataSource = this.DttGrid;
//on stylise la datagridview
this.StyleDtg ();
//rafraichissement de la fenetre
this.Show ();
//on ferme la connection
this.Conn.Close ();



}
}
}
 

Actually, i dont know how put the datas in the good fields (sorry for my english). When i create :

object LatitudeIndex = 3;
object LongitudeIndex = 2; etc ...

and data field...

because i have an error :s. If you will have a very simple example. Because your example in the datasheet isn't very explicit :s. And even on the msd there is always the same part of code ... (paye ton travail en deux deux). And never a very good example to use an access 2003 data base and mappoint 2006.

I thank you very much.

And all my apologies for all of these questions.

regards,
Reply With Quote