`

在C#应用中如何读取存在ORACLE(或SQL Server)中的MapInfo表

阅读更多

   using MapInfo.Data;           //这里要添加对MapInfo数据的引用
   MIConnection Connection=new MIConnection();
   Connection.Open();
   MapInfo.Data.Table [] tables=new MapInfo.Data.Table[4];
   TableInfoServer tis1=new TableInfoServer("WORLD","SVR=MYORACLE;UID=system;PWD=manager","select * from world",MapInfo.Data.ServerToolkit.Oci);
   tables[0]=Connection.Catalog.OpenTable(tis1);
   TableInfoServer tis2=new TableInfoServer("WORLDCAP","SVR=MYORACLE;UID=system;PWD=manager","select * from worldcap",MapInfo.Data.ServerToolkit.Oci);
   tables[1]=Connection.Catalog.OpenTable(tis2);
   TableInfoServer tis3=new TableInfoServer("wldcty25","SVR=MYORACLE;UID=system;PWD=manager","select * from wldcty25",MapInfo.Data.ServerToolkit.Oci);
   tables[2]=Connection.Catalog.OpenTable(tis3);
   TableInfoServer tis4=new TableInfoServer("OCEAN","SVR=MYORACLE;UID=system;PWD=manager","select * from OCEAN",MapInfo.Data.ServerToolkit.Oci);
   tables[3]=Connection.Catalog.OpenTable(tis4);
   MapControl1.Map.Load(new MapInfo.Mapping.MapTableLoader(tables));
   Connection.Close();
  而读取存放在SQL Server2000中的表时,应当使用如下修改过的代码:
   /* SQL Server数据库连接*/
   MIConnection Connection=new MIConnection();
   Connection.Open();
   MapInfo.Data.Table [] tables=new MapInfo.Data.Table[2];
   TableInfoServer tis1=new TableInfoServer("CH_SHENGHUI","DRIVER={SQL Server};SERVER=YC31;DATABASE=MYWEBGIS;Trusted_Connection=Yes","select * from CH_SHENGHUI",MapInfo.Data.ServerToolkit.Odbc);//注意这里使用的是Odbc,且区分大小写。
   tables[0]=Connection.Catalog.OpenTable(tis1);
   TableInfoServer tis2=new TableInfoServer("CH_SHENGJIE_P","DRIVER={SQL Server};SERVER=YC31;DATABASE=MYWEBGIS;Trusted_Connection=Yes","select * from CH_SHENGJIE_P",MapInfo.Data.ServerToolkit.Odbc);//注意这里使用的是Odbc,且区分大小写。
   tables[1]=Connection.Catalog.OpenTable(tis2);
   mapControl1.Map.Load(new MapInfo.Mapping.MapTableLoader(tables));
   Connection.Close();
   /*上面的TableInfoServer语句分开来写可以表达成如下方法。*/
   /*
   TableInfoServer tiServer = new TableInfoServer("SHENGHUI");
   tiServer.ConnectString = "DRIVER={SQL Server};SERVER=YC31;DATABASE=MYWEBGIS;Trusted_Connection=Yes";
   tiServer.Query = "Select * from CH_SHENGHUI";
   tiServer.Toolkit = ServerToolkit.Odbc;
   MapTableLoader tl = new MapTableLoader(tiServer);
   mapControl1.Map.Load(tl);
   */
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics