//把所有的字段都读进来
private void Form2_Load(object sender, EventArgs e)
{int i;
ILayer pLayer=mFormShow1.axMapControl1.Map.get_Layer(0);
IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IField pField;
for (i = 0; i < pFeatureClass.Fields.FieldCount; i++)
{
pField = pFeatureClass.Fields.get_Field(i);
comboBox1.Items.Add(pField.Name);
}
}
//根据条件进行查询
private void button1_Click(object sender, EventArgs e)
{
ILayer pLayer = mFormShow1.axMapControl1.get_Layer(0);
IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)pLayer;
ITable pTable = (ITable)pGeoFeatureLayer;
IQueryFilter pQueryFilter = new QueryFilterClass();
IFeatureCursor pFeatureCursor;
ICursor pCursor;
IFeature pFeature;
pQueryFilter.WhereClause = comboBox1.Text + comboBox2.Text + textBox1.Text;
pCursor = pTable.Search(pQueryFilter, true);
pFeatureCursor = (IFeatureCursor)pCursor;
pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
mFormShow1.axMapControl1.Map.SelectFeature(pGeoFeatureLayer, pFeature);
pFeature = pFeatureCursor.NextFeature();
}
mFormShow1.axMapControl1.Refresh();
int RowCount = pTable.RowCount(pQueryFilter);
MessageBox.Show(RowCount.ToString());
}