Probleme with access 2003 and MapPoint 2006

black_fox_71
04-30-2008, 02:37 AM
Hi,

I devellop an application in C# to use mapPoint and Access query.


So in first time, i created a code which create a data base. My code works, this is very very very slow. BUT it works.


In second time i created an other application to make query on my data base and i display results on a datagridview. And again my code works.


And now, i add a mapPoint control. Just the control and i load a map. So i make a query on my data base it works, i load the MapPoint control, it works too, i make an other query on my data base, the application crash.


this my 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 Recherche_BDD_1

{

publicpartialclassForm1 : Form

{

public Form1()

{

InitializeComponent();

}


//MapPoint.Symbols all;

String objTemplate = "C:/Program Files/Microsoft MapPoint Europe/Templates/Nouvelle carte d'Europe.ptt";

MapPoint.Map objMap = null;


privatevoid Form1_Load(object sender, EventArgs e)

{



}


privatevoid button1_Click(object sender, EventArgs e)

{


MapPoint.Map objMap = null;


string connString = @"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=Contacts.mdb";

if (File.Exists("Contacts.mdb") == true)

{

OleDbConnection conn = newOleDbConnection(connString);

conn.Open();

string query = "SELECT * FROM Contacts Where Rue = 'Avenue Du 14 Juillet'";

OleDbDataAdapter adapter = newOleDbDataAdapter(query, conn);

DataSet datas = newDataSet();

adapter.Fill(datas);

conn.Close();

adapter = null;

conn = null;

dataGridView1.DataSource = datas.Tables[0];

datas = null;


}

else

{

MessageBox.Show("Erreur le fichier n'existe pas");

}


}

privatevoid dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

}

privatevoid button_Erase_Data_Click(object sender, EventArgs e)

{

axMappointControl1.NewMap(objTemplate);

objMap = axMappointControl1.ActiveMap;

objMap.MapStyle = MapPoint.GeoMapStyle.geoMapStyleData;

}

}

}




Like you can see, this is very simple. just a query, and load a map.


I use the following programs :


Access 2003,

Visual studios 2005,

windows XP pro SP2 version 2002,

MapPoint 2006,

All of these version are in french.



The debbuger give me the following error code :


Le moteur de base de données Microsoft Jet ne peut pas trouver la table ou la requête source 'Contacts'. Assurez-vous qu'elle existe et qu'elle est correctement orthographiée.


=> translation : The data base controle of Microsoft Jet cannot find the data base or the source query 'Contacts'. Look if it exist and it is correctly misspelled.


Error code : -2147217865,


I search on the web where can come from the problem. And i fund just an answer which can join my problem.


VS 2005 & Access DB problem - MSDN Forums (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=150425&SiteID=1)


I installed a patch, change some options. But i have always the same problem.:saddam:


If you have an example of code which can be better. Or if there is an error in my code. Please inform me :p.


I Thank you.

black_fox_71
05-06-2008, 02:57 AM
Hi,

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

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 :rockstar:.

I give you a part of my 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(DataGridViewAutoSizeColumnsM ode.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.geoData MapTypeShadedCircle,
datafields, MapPoint.GeoShowDataBy.geoShowByLatLong,
MapPoint.GeoCombineDataBy.geoCombineByDefault,
MapPoint.GeoDataRangeType.geoRangeTypeDiscreteEqua lRanges,
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.:surprised:

regards,

Wilfried
05-06-2008, 06:51 AM
Hi,

Can you tell us what the error is and the offending code line?

black_fox_71
05-06-2008, 07:46 AM
Hi,

The error is at the end of code, when i use :

//affichage avec définition de l'échelle (couleur et intervalle)
MapPoint.DataMap datamap = oDS.DisplayDataMap(MapPoint.GeoDataMapType.geoData MapTypeShadedCircle,
datafields, MapPoint.GeoShowDataBy.geoShowByLatLong,
MapPoint.GeoCombineDataBy.geoCombineByDefault,
MapPoint.GeoDataRangeType.geoRangeTypeDiscreteEqua lRanges,
MapPoint.GeoDataRangeOrder.geoRangeOrderLowToHigh,
12, 8, myranges, missing, missing, missing, missing);

I have the following error :

{"Paramètre incorrect.\r\n"}

=> Wrong parameters :7m:

I'm sure what i forget something, and as i said, i dont know how use datamap. I watched the datasheet for avoid syntax error. But even with that i dont know how use access with MapPoint.


Moreover, my data base is like this example :

data data "Longitude" "Latitude" data data data data "Average<=>(Moyenne)" data data data

Thank you for your answer.

regards;

Eric Frost
05-06-2008, 10:12 AM
It's not an Access problem.. it's DisplayDataMap.

It will kick out that error if *any* of the parameters are incorrect or don't match what it expects..

My stock answer is to read the sections in "Programming MapPoint in .NET" as I always go back and refer to it when I am working with DisplayDataMap myself...

I keep thinking I should create a guide or article on DisplayDataMap on MP2Kmag.com but I haven't gotten around to it. :shout:

Eric

Wilfried
05-06-2008, 11:59 AM
Hi,

Since all (or most of the) arguments to this method are optional you can find out which one is the offending one if you start with only a few arguments and increase one by one.

black_fox_71
05-07-2008, 08:27 AM
Hi,

I thank you, for your answers. I didn t found where is the wrong parameter, but i used an other data source, with text file :freak:.

I make a request, i write the results in a text file. And i use this file as data source. My code works :-D.

I will search for access data base, moreover i had already watched fiew pages of "Programming MapPoint in .NET" Eric.

On this site :

Programming MapPoint in .NET - Google Recherche de Livres (http://books.google.fr/books?id=Rcw43Dm9dbkC&pg=PA93&lpg=PA93&dq=mappoint+datamap+&source=web&ots=oykIFxuhyX&sig=L3_VSM6MJgiqmI_ssmNvz5oeWow&hl=fr#PPA93,M1)

There is few page of this book. So perhaps, if i sell one of my kidney one day. I will buy this book :drool5:.

Thank you for your answers again.

 
Web mp2kmag.com
mapforums.com