MapPoint Forums

MapForums

Community of MapPoint and Virtual Earth Users and Developers




c# ImportData method help needed

This is a discussion on c# ImportData method help needed within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; I am trying to write a tool in C# and am having difficulty with the ImportData method. Can anybody see ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Today's Posts Twitter Feed Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-28-2005
Junior Member
White Belt
 
Join Date: Feb 2005
Posts: 8
c# ImportData method help needed

I am trying to write a tool in C# and am having difficulty with the ImportData method.
Can anybody see something wrong with this piece of code
Code:
axMappointControl1.ActiveMap.DataSets.ImportData("c:\\filename.xls",null ,MapPoint.GeoCountry.geoCountryUnitedKingdom,MapPoint.GeoDelimiter.geoDelimiterDefault,MapPoint.GeoImportFlags.geoImportExcelSheet);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
I've used C# to import from different kinds of databases, but never and excel sheet, so I'm not sure if this will help, especially since I dont know what kind of problem or errors you are getting from that code.

I think that if you do not want to use an array of fields, you should leave that field empy, not NULL. Also, I believe that when you use and excel sheet you have to give it the sheet name as well as the file name.

e.g. "c:\\filename.xls!NameOfSheet"

As I said, you didnt really specify what kind of problem you are having, but if I were going to try to import from excel, I would do:

Code:
axMappointControl1.ActiveMap.DataSet MyData;
MyData=ImportData("c:\\filename.xls!NameOfSheet",,MapPoint.GeoCountry.geoCountryUnitedKingdom,MapPoint.GeoDelimiter.geoDelimiterDefault,MapPoint.GeoImportFlags.geoImportExcelSheet);
I havn't tested that code, but its what I would use in that situations
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2005
Junior Member
White Belt
 
Join Date: Feb 2005
Posts: 8
Thanks for the help GxW34....
I have modified the code and it is now building without errors however I am getting the following error message at runtime(when I click the button)
Code:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication3.exe

Additional information: No matching method defined for these fields.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
That one is new to me. If you could maybe post a little bit more of your code, or explain what it is your trying to do I might be able to help you out a little better
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 03-01-2005
Junior Member
White Belt
 
Join Date: Feb 2005
Posts: 8
Quote:
Originally Posted by GxW34
That one is new to me. If you could maybe post a little bit more of your code, or explain what it is your trying to do I might be able to help you out a little better
Basically I am just trying to import a small spreadsheet of data from an excel spreadsheet & display it on a map(This is a simplified version, once I get this working I will be expanding on it, I just want the basic functionality working first Here's the code so far
Code:
public class Form1 : System.Windows.Forms.Form
	{
		private AxMapPoint.AxMappointControl axMappointControl1;
      private MapPoint.DataSet myData; 
         }
         private void button7_Click(object sender, System.EventArgs e)
		{
                           				myData = axMappointControl1.ActiveMap.DataSets.ImportData("c:\\filename.xls!Sheet1",null,MapPoint.GeoCountry.geoCountryUnitedKingdom,MapPoint.GeoDelimiter.geoDelimiterDefault,MapPoint.GeoImportFlags.geoImportExcelSheet); 	
                }
filename.xls contains the following information in Sheet1
1250000 Manchester
3500000 London
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 03-02-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
I know it been a while, I got very busy and havent had a chance to get to the forumn in a while. If you are still having the same problem, Im pretty sure it is because you are importing data that Mappoint can not map. It is trying to display the data on the map, and it does not know where

1250000 Manchester

is on a map, so it does not know what to do with that data.

Matching methods are the way mappoint figures out where the location is, there are a few or them, but the Latitude and Longitude usually work the best.

I created a small program that imports two records from an excel sheet, and it displays them on the map and works fine


Code:
private void button1_Click(object sender, System.EventArgs e)
		{
			MapPoint.DataSet myData;
			myData = axMappointControl1.ActiveMap.DataSets.ImportData("c:\\filename.xls!Sheet1",null,MapPoint.GeoCountry.geoCountryUnitedKingdom,MapPoint.GeoDelimiter.geoDelimiterDefault,MapPoint.GeoImportFlags.geoImportExcelSheet);     
		}
the xls file contains,
Latitude Longitude Name
36.1245 -90.1234 Spot1
36.2561 -90.8945 Spot2

If this doesnt help, or if I am misunderstanding your problem, reply and Ill try to get back faster this time
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 03-03-2005
Junior Member
White Belt
 
Join Date: Feb 2005
Posts: 8
Thanks for the help GxW34
The problem was that I did not specify the headings of the fields in the excel spreadsheet. It works now that the spreadsheet looks like so:
Other Data City
1250000 Manchester
3500000 London

However I have run into further difficulties. If a field is not found during the importData method, is there any way of displaying/storing this data? I know the .QueryAllRecords() method returns all the records (matched, unmatched, and skipped) in a data set, however it does not contain the name of the record that was skipped so there is no way of displaying the unmatched records....any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 03-03-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
There might be an easier way to do this, but whenever I import data from a database (I assume it will work the same for excel), I use the array of fields paramater. That way I know exactly what fields will be imported, what they will be named and how they will be treated by mappoint.

Code:
object[,] ImportData = new object[2,2];
ImportData[0,0] = "Whatever";
ImportData[0,1] = MapPoint.GeoFieldType.geoFieldData;
ImportData[1,0] = "Name";
ImportData[1,1] = MapPoint.GeoFieldType.geoFieldName;
object whatever = "Whatever";
object name = "Name";
MapPoint.Field NameField;
MapPoint.Field WhateverField;
MapPoint.DataSet DS;
MapPoint.Recordset RS;

DS = axMappointControl1.ActiveMap.DataSets.ImportData("c:\\filename.xls!Sheet1",ImportData,MapPoint.GeoCountry.geoCountryUnitedKingdom,MapPoint.GeoDelimiter.geoDelimiterDefault,MapPoint.GeoImportFlags.geoImportExcelSheet);
RS = DS.QueryAllRecords();
RSet.MoveFirst();
while(!RSet.EOF) 
{
    WhateverField = RS.Fields.get_Item(ref whatever);
    NameField = RS.Fields.get_Item(ref name);
    MessageBox.Show(WhateverField.Value.ToString() + " - " + NameField.Value.ToString());
    RSet.MoveNext();
}
This code will display a message box with the values for each record in you excel sheet.

I didnt really test that code, and I wrote it of the top of my head, so there may be few syntax errors but you should get the idea.

Hope this helps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 03-09-2005
Junior Member
White Belt
 
Join Date: Feb 2005
Posts: 8
Quote:
Originally Posted by GxW34
There might be an easier way to do this, but whenever I import data from a database (I assume it will work the same for excel), I use the array of fields paramater. That way I know exactly what fields will be imported, what they will be named and how they will be treated by mappoint.

Code:
object[,] ImportData = new object[2,2];
ImportData[0,0] = "Whatever";
ImportData[0,1] = MapPoint.GeoFieldType.geoFieldData;
ImportData[1,0] = "Name";
ImportData[1,1] = MapPoint.GeoFieldType.geoFieldName;
object whatever = "Whatever";
object name = "Name";
MapPoint.Field NameField;
MapPoint.Field WhateverField;
MapPoint.DataSet DS;
MapPoint.Recordset RS;

DS = axMappointControl1.ActiveMap.DataSets.ImportData("c:\\filename.xls!Sheet1",ImportData,MapPoint.GeoCountry.geoCountryUnitedKingdom,MapPoint.GeoDelimiter.geoDelimiterDefault,MapPoint.GeoImportFlags.geoImportExcelSheet);
RS = DS.QueryAllRecords();
RSet.MoveFirst();
while(!RSet.EOF) 
{
    WhateverField = RS.Fields.get_Item(ref whatever);
    NameField = RS.Fields.get_Item(ref name);
    MessageBox.Show(WhateverField.Value.ToString() + " - " + NameField.Value.ToString());
    RSet.MoveNext();
}
This code will display a message box with the values for each record in you excel sheet.

I didnt really test that code, and I wrote it of the top of my head, so there may be few syntax errors but you should get the idea.

Hope this helps
Hey, thanks for your suggested code. One small problem is that I do not know prior to running the ImportData() method, the headings that the data will come under so I'm using a more generic method.
I cannot seem to be able to extract the names of the unmatched records from the data set, is this possible?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
importdata, method, needed


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
ImportData method ? mgorgone MapPoint 2006/2009 Discussion 2 06-02-2005 01:31 PM
import query with importdata method in VB.net Anonymous MapPoint 2006/2009 Discussion 3 01-20-2004 10:30 AM
Get an error 4055 by using method ImportData Anonymous MapPoint 2006/2009 Discussion 1 12-21-2003 12:27 PM
ImportData method doesn't function Val MapPoint 2006/2009 Discussion 3 12-01-2003 09:27 AM
How ImportData method with "Password-protected" a rrosenhagen MapPoint 2006/2009 Discussion 0 12-10-2002 03:13 PM


All times are GMT -5. The time now is 01:05 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 RC2
MP2K Magazine
Visitor Map

Ibiza Holiday
Visit the party capital of Europe with an Ibiza holiday! Check out the deals online on UlookUbook...



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 57 58 59