private void showMap()
{
MIDataReader tr;
MIConnection con=new MIConnection();
MICommand tc=con.CreateCommand();
tc.CommandText="select 村 from 农安 where PH__2002 > 8.5";
//sql语句
con.Open();
IFeatureCollection fc = tc.ExecuteFeatureCollection();
//得到Features集合
tr=tc.ExecuteReader();
while (tr.Read())
{
Response.Write(tr.GetString(0)+" ");
//显示搜索到的信息
}
tc.Cancel();
tc.Dispose();
tr.Close();
con.Close();
IResultSetFeatureCollection ff = (IResultSetFeatureCollection)fc;
//强行转化为IResultSetFeatureCollection
if (MapInfo.Engine.Session.Current.Selections.DefaultSelection.Style.AreaStyle.Interior is SimpleInterior)
{
((SimpleInterior)MapInfo.Engine.Session.Current.Selections.DefaultSelection.Style.AreaStyle.Interior).BackColor = Color.Red;
//更改DefaultSelection的背景颜色
}
MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();
MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add(ff);
//添加到DefaultSelection中 用户可见到效果
}
这段代码主要实现了数据库查询及地图显示功能。通过创建数据库连接、执行SQL语句查询农安表中PH__2002大于8.5的村信息,将结果显示出来。还对地图选择区域的样式进行了设置,如更改背景颜色,并将查询结果添加到默认选择中。
134

被折叠的 条评论
为什么被折叠?



