MAPX reads data from a database to form a new layer (C #)

Source: Internet
Author: User
Tags count requires
Data | database

mapx read data from the database to form a new layer (C #) 2005-5-10 implementation of MAPX in C # reading data from a database to form a new layer is divided into two problems:1.         MAPX reads data from the database to form a new layer;2.         transforms the DataTable into an ADO recordset. The second problem here is caused by the first problem, because MAPX is a COM control, and it only supports ADO data access, while C # programming typically uses the ado.net approach, which requires a conversion between the two ways. (Of course, you can also use ADO in C #, but this is a backward method.) This workaround can refer to the article "Accessing the database using ADO in Visual Basic.NET"). For the solution to the second question, see the author's other article, "Converting a DataTable object to a Recordset object" (http://blog.csdn.net/allentao/archive/2005/05/11/373634). aspx), this article only describes how to solve the first problem after you get the Recordset object. The steps below:1.         create the Cmapxfields object and Add fields to the fields in the database;2.          Create a Cmapxbindlayer object that specifies the ordinal of its coordinate value field;3.          to map. Add a dataset to the datasets to generate a new layer;4.         specify the display style of the elements in the new layer, using the display bitmap, This requires that the bitmap to be displayed be placed under the Custsymb folder of the MAPX installation directory.

The code is as follows: private void Creatnewlayerfromdb (String layername, ADODB. Recordset rsnopass) {this.   Deletelayerbyname (LayerName); Remove an existing layer

Cmapxfields flds=new Fieldsclass ();

                      //Describe The structure of the unbound dataset                      FLDS. ADD ("Stationid", "Theid", aggregationfunctionconstants.miaggregationindividual,                              fieldtypeconstants.mitypestring);                      FLDS. ADD ("Address", "address", Aggregationfunctionconstants.miaggregationindividual,                               fieldtypeconstants.mitypestring);                      FLDS. ADD ("Longitude", "longitude", Aggregationfunctionconstants.miaggregationsum,                               fieldtypeconstants.mitypenumeric); //Longitude                       FLDS. ADD ("Latitude", "latitude", Aggregationfunctionconstants.miaggregationsum,                               fieldtypeconstants.mitypenumeric); //Latitude

                       cmapxbindlayer bindlayerobject=new bindlayerclass ();                      bindlayerobject.layername= layername;                      bindlayerobject.refcolumn1=3;                      bindlayerobject.refcolumn2=4;                      Bindlayerobject.layertype=bindlayertypeconstants.mibindlayertypexy;

                       Cmapxdataset Dataset=map. Datasets.add (Datasettypeconstants.midatasetado,                              Rsnopass , LayerName, "Stationid", "Address", Bindlayerobject, FLDS, false);

                       Cmapxlayer Layer=map. Layers._item (LayerName);                      layer. Overridestyle= true;                      string Picname= "icon. BMP ";                      if (layer. Style.supportsbitmapsymbols = = true)                       {                             layer. Style.symboltype = symboltypeconstants.misymboltypebitmap;                             layer. Style.symbolbitmapsize = 60;                             layer. Style.symbolbitmaptransparent = true;                             layer. Style.symbolbitmapname = picname;                     }                                                           }

               private void Deletelayerbyname (string layername)                {                      int Count=map. layers.count;                      for (int i=1; i<count; i++)                       {                              if (map. Layers._item (i). Name==layername)                                     map. Layers.remove (i);                     }             }

Description: The number of the MAPX control is starting from 1, which can be seen from the layers collection and the serial number of the fields set in the above code.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.