Select to view content in your preferred language

ArcMap Crashes while running query.

685
3
10-07-2010 12:58 AM
BiswajitSaha
Emerging Contributor
i am trying to select features by querying two field as Plot_No (integer field ) and Layer(Text Field) but failed due to ArcMap crashing. i guess there might be problem at whereclause section. I couldnt figure out the solution. I am looking forward to your response. I am sure that your little effort can help me more.


amespace nayan1
{
public partial class Form1 : Form
{
IMxDocument mxd;
IFeatureLayer flayer;
IFeatureClass fclass;


public Form1()
{
InitializeComponent();

}


private void Form1_Load(object sender, EventArgs e)
{
mxd = ArcMap.Application.Document as IMxDocument;
IMap map = mxd.FocusMap;
flayer = map.get_Layer(0) as IFeatureLayer;
fclass = flayer.FeatureClass;
IDataStatistics_Example(fclass);


}

private void button1_Click(object sender, EventArgs e)
{
mxd = ArcMap.Application.Document as IMxDocument;
IMap map = mxd.FocusMap;
flayer = map.get_Layer(0) as IFeatureLayer;
fclass = flayer.FeatureClass;
IFeatureSelection fsel = flayer as IFeatureSelection;
IQueryFilter qfilter = new QueryFilterClass();
  qfilter.WhereClause = "Plot_No = textBox1.Text AND Layer =Convert.ToString( comboBox1.SelectedItem)";


fsel.SelectFeatures(qfilter, esriSelectionResultEnum.esriSelectionResultNew, false);
mxd.ActiveView.Refresh();
int x = map.SelectionCount;
if (x == 0)
{
MessageBox.Show("nothing is selected");
}

}
public void IDataStatistics_Example(IFeatureClass featureClass)
{
ICursor cursor = (ICursor)featureClass.Search(null, false);

IDataStatistics dataStatistics = new DataStatisticsClass();
dataStatistics.Field = "Layer";
dataStatistics.Cursor = cursor;

System.Collections.IEnumerator enumerator = dataStatistics.UniqueValues;
enumerator.Reset();

while (enumerator.MoveNext())
{
object myObject = enumerator.Current;
comboBox1.Items.Add(myObject);
}

Anyway, thanking You in Advance...

best regards
biswajit Saha
0 Kudos
3 Replies
ThavitinaiduGulivindala
Regular Contributor
Hi,

qfilter.WhereClause = "Plot_No = " + textBox1.Text " AND Layer = '" + comboBox1.SelectedItem.tostring()+"'";
0 Kudos
KenBuja
MVP Esteemed Contributor
You have to separate the text parts of the query from the values derived from the controls. Try this for your whereclause string

qfilter.WhereClause = "Plot_No = " & textBox1.Text & " AND Layer = '" & Convert.ToString( comboBox1.SelectedItem) & "'";
0 Kudos
BiswajitSaha
Emerging Contributor
thank u very much thaviti......by just a additional + to ur code resolve my problem.

qfilter.WhereClause = "Plot_No = " + textBox1.Text +" AND Layer = '" + comboBox1.SelectedItem.tostring()+"'";
0 Kudos