将sql server数据库表中的字段绑定到表usa的例子

将sql server数据库表中的字段绑定到表usa的例子
//绑定远程属性数据表(sql server)
//打开地图目标表
Table targetTbl=Session.Current.Catalog.OpenTable (@"C:\Program
Files\MapInfo\Professional\Data\Map_Data\Namerca\USA\Usa_Maps\USA.tab");
FeatureLayer targetLyr=new FeatureLayer (targetTbl,"targetTbl","TargetTable");
mapControl1.Map.Layers.Add (targetLyr);
//打开数据源表(在sql server中),表中需要要唯一关键字段。
MapInfo.Data.TableInfoServer ti=new  TableInfoServer("sourcetable");
ti.ConnectString ="Driver={SQL Server};Server=Lixiaohui;database=test; Uid=sa; Pwd=sa;";
ti.Query="select * from us_cust";
ti.Toolkit=MapInfo.Data.ServerToolkit.Odbc;
Table srcTbl=Session.Current.Catalog.OpenTable(ti);
MessageBox.Show (this,srcTbl.TableInfo.Columns.Count.ToString());
//从源表中将字段加入到目标表,以state(州名)字段为连接字段,加入的字段为以州为单位的订单数。
Columns cols=new Columns();
cols.Add (new Column("sumOrder",MIDbType.Int,"Sum(ORDER_AMT)"));
targetTbl.AddColumns (cols,MapInfo.Data.BindType.Static,srcTbl,"Upper(STATE)",MapInfo.Data.Operator.Equal,"Upper(State)");

posted @ 2009-12-14 16:19  googlegis  阅读(167)  评论(0编辑  收藏  举报

坐标合肥,非典型GIS开发人员 GitHub