Community of MapPoint and Virtual Earth Users and Developers
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 ...
| |||||||
| Today's Posts | Twitter Feed | Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| c# ImportData method help needed 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);
|
| |||
|
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);
|
| |||
|
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. |
| |||
| Quote:
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);
}
1250000 Manchester 3500000 London |
| |||
|
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);
}
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 |
| |||
|
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? |
| |||
|
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();
}
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 |
| |||
| Quote:
I cannot seem to be able to extract the names of the unmatched records from the data set, is this possible? |
![]() |
| Tags |
| importdata, method, needed |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| 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 |
Ibiza Holiday
Visit the party capital of Europe with an Ibiza holiday! Check out the deals online on UlookUbook...