Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 9 of 9

c# ImportData method help needed

This is a discussion on c# ImportData method help needed within the MapPoint Desktop 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 ...

  1. #1
    fletch is offline 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);

  2. #2
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    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

  3. #3
    fletch is offline 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.

  4. #4
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    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

  5. #5
    fletch is offline 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

  6. #6
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    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

  7. #7
    fletch is offline 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?

  8. #8
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    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

  9. #9
    fletch is offline 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?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. ImportData method ?
    By mgorgone in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 06-02-2005, 02:31 PM
  2. import query with importdata method in VB.net
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 01-20-2004, 11:30 AM
  3. Get an error 4055 by using method ImportData
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-21-2003, 01:27 PM
  4. ImportData method doesn't function
    By Val in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 12-01-2003, 10:27 AM
  5. How ImportData method with "Password-protected" a
    By rrosenhagen in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 12-10-2002, 04:13 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96