trouble shoot about using BindLayer in MapX with C# [原创]
2008-11-01 15:44
411 查看
If you have problem about using BindLayer in MapX with C#, check this out. it may help.
My Enviroment:Microsoft Visual Studio.NET 2005 (C#) + Mapinfo MapX 5.02
Keywords: BindLayer ,DataSet,ADO,MapX,C#
Let's cut the bullshit, If you want to follow the VB6 sample to add a new bindlayer into your application,
congrats, you will make most of your time waste. the .NET make things different. the old good time
passed away and never back again.
Step 1: you have to add 2 COM reference into your application : ADODB also named Microsoft ActiveX Data Object 2.8
MapX 5.0,why ADODB, cause the fucking .NET dataset will not work with MapX.
Setp 2: If you want to set you bindlayer style to miBindLayerTypeXY ,you need modify you database firstly, for example, you have to add new primary key columen into you database named like "MYID" in this sample . if you dont do so, there will be an error like "NOT FOUND GeoField or BindLayer".i bet you wont like that.
Step 3: Copy these code into your program.you may change a little bit to fit your request.
Done!
========================================================================
private string m_strConnString;
private ADODB.Connection m_cnn;
private ADODB.Recordset m_rds;
private ADODB.Recordset RetriveDataFromDB(string pConnString)
{
m_strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Fart\\DB\\TestDB.mdb";
m_bndlyrName = "MyBindlayer"; //Set your bindlayer name here
m_cnn = new ADODB.Connection();
m_rds = new ADODB.Recordset();
m_cnn.Open(m_strConnString, null, null, -1);
m_rds.ActiveConnection = m_cnn;
m_rds.Open("SELECT MYID, Longitude_X,Latitude_Y FROM GUANRUI_TEST_TBL", m_cnn, ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockOptimistic, 1);
return m_rds;
}
private void DoBindLayer(ADODB.Recordset pDs)
{
MapXLib.BindLayer BindLyr;
MapXLib.Dataset miDS;
MapXLib.FieldsClass flds;
miDS = null;
flds = new MapXLib.FieldsClass();
BindLyr = new MapXLib.BindLayer();
flds.Add("MYID", "MYID", MapXLib.AggregationFunctionConstants.miAggregationIndividual,
MapXLib.FieldTypeConstants.miTypeNumeric);
flds.Add("Longitude_X", "Longitude_X", MapXLib.AggregationFunctionConstants.miAggregationIndividual,
MapXLib.FieldTypeConstants.miTypeNumeric);
flds.Add("Latitude_Y", "Latitude_Y", MapXLib.AggregationFunctionConstants.miAggregationIndividual,
MapXLib.FieldTypeConstants.miTypeNumeric);
BindLyr.LayerType = MapXLib.BindLayerTypeConstants.miBindLayerTypeXY;
BindLyr.RefColumn1 = "Longitude_X";
BindLyr.RefColumn2 = "Latitude_Y";
BindLyr.LayerName = m_bndlyrName;
//BindLyr.FileSpec = Application.StartupPath+ "\\DB\\Test.tab";
//BindLyr.OverwriteFile = true;
miDS = axMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetADO, pDs, BindLyr.LayerName,
"MYID", System.Reflection.Missing.Value, BindLyr, flds, false);
}
My Enviroment:Microsoft Visual Studio.NET 2005 (C#) + Mapinfo MapX 5.02
Keywords: BindLayer ,DataSet,ADO,MapX,C#
Let's cut the bullshit, If you want to follow the VB6 sample to add a new bindlayer into your application,
congrats, you will make most of your time waste. the .NET make things different. the old good time
passed away and never back again.
Step 1: you have to add 2 COM reference into your application : ADODB also named Microsoft ActiveX Data Object 2.8
MapX 5.0,why ADODB, cause the fucking .NET dataset will not work with MapX.
Setp 2: If you want to set you bindlayer style to miBindLayerTypeXY ,you need modify you database firstly, for example, you have to add new primary key columen into you database named like "MYID" in this sample . if you dont do so, there will be an error like "NOT FOUND GeoField or BindLayer".i bet you wont like that.
Step 3: Copy these code into your program.you may change a little bit to fit your request.
Done!
========================================================================
private string m_strConnString;
private ADODB.Connection m_cnn;
private ADODB.Recordset m_rds;
private ADODB.Recordset RetriveDataFromDB(string pConnString)
{
m_strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Fart\\DB\\TestDB.mdb";
m_bndlyrName = "MyBindlayer"; //Set your bindlayer name here
m_cnn = new ADODB.Connection();
m_rds = new ADODB.Recordset();
m_cnn.Open(m_strConnString, null, null, -1);
m_rds.ActiveConnection = m_cnn;
m_rds.Open("SELECT MYID, Longitude_X,Latitude_Y FROM GUANRUI_TEST_TBL", m_cnn, ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockOptimistic, 1);
return m_rds;
}
private void DoBindLayer(ADODB.Recordset pDs)
{
MapXLib.BindLayer BindLyr;
MapXLib.Dataset miDS;
MapXLib.FieldsClass flds;
miDS = null;
flds = new MapXLib.FieldsClass();
BindLyr = new MapXLib.BindLayer();
flds.Add("MYID", "MYID", MapXLib.AggregationFunctionConstants.miAggregationIndividual,
MapXLib.FieldTypeConstants.miTypeNumeric);
flds.Add("Longitude_X", "Longitude_X", MapXLib.AggregationFunctionConstants.miAggregationIndividual,
MapXLib.FieldTypeConstants.miTypeNumeric);
flds.Add("Latitude_Y", "Latitude_Y", MapXLib.AggregationFunctionConstants.miAggregationIndividual,
MapXLib.FieldTypeConstants.miTypeNumeric);
BindLyr.LayerType = MapXLib.BindLayerTypeConstants.miBindLayerTypeXY;
BindLyr.RefColumn1 = "Longitude_X";
BindLyr.RefColumn2 = "Latitude_Y";
BindLyr.LayerName = m_bndlyrName;
//BindLyr.FileSpec = Application.StartupPath+ "\\DB\\Test.tab";
//BindLyr.OverwriteFile = true;
miDS = axMap1.DataSets.Add(MapXLib.DatasetTypeConstants.miDataSetADO, pDs, BindLyr.LayerName,
"MYID", System.Reflection.Missing.Value, BindLyr, flds, false);
}
相关文章推荐
- Using Weka and Libsvm with C# in Visual Studio
- Exception handling with custom error pages in ASP.NET using C#.
- Quick Trick About Using Dbms_Metadata With Forms_DDL In Oracle Forms
- Handle unmanaged code in managed c# with the help of using statement
- Working with PDF files in C# using PdfBox and IKVM
- Creating a Web Control with an Expandable Property in the Designer by Using C#.
- Using the SAS® SDW fails with a Secure Socket Layer (SSL) in Weblogic10.3
- Alternative solution for using IF condition with Eval in C# Repeater
- [寻书]请问谁有《Pragmatic Unit Testing in C# with NUnit 》的电子版,请发给我一下,谢谢!
- [资料收集]All about Unsafe Code in C#
- #466 – 将GridSplitter和SharedSizeGroup联合使用(Using a GridSplitter in Conjunction with a SharedSizeGroup)
- Obtaining (and managing) file and folder icons using SHGetFileInfo in C#
- about data type in c#
- Any problem in computer science can be solved with another layer of indirection
- [转]Using Pointers in C#
- Working with JSON in C#
- Using Attributes in C#
- Generate mp4 video with image files using MediaCodec in Android
- Simple example for transform xml with xlst in C#
- How to troubleshoot the “Red Arrow” issue in Component Services (II)