Select to view content in your preferred language

A Simple Query of a FeatureClass (Help Please)

647
4
09-29-2010 08:06 AM
AkhilParujanwala
Regular Contributor
Hi,

I am trying to simply query a featureclass in the mobile cache.
I want to retrieve the record where TEAM_ID = Team A.
When I select that record, I want to get the value of a particular field and store it.

Please help me, here is some sample code

FeatureLayer featureLayer = MobileApplication.Current.Project.FindFeatureLayer("Field Crew Teams");
                    
QueryFilter pQFilter;
string whereClause = "TEAM_ID = Team A";
pQFilter = new QueryFilter(whereClause, true);                 
                    
FeatureDataReader featDataReader = featureLayer.GetDataReader(pQFilter);



The code is also stating that QueryFilter is obsolete, so I am also trying to use QueryDefinition but I don't know which reference I am suppose to add.

Please help me out,

Thanks,

Akhil P.
0 Kudos
4 Replies
MelindaFrost
Frequent Contributor
Try using single quotes around the value.
string whereClause = "TEAM_ID = 'Team A'";
0 Kudos
AkhilParujanwala
Regular Contributor
Thanks buddha the apostrophe's allowed the QueryFilter to work, but now I am having problems trying to create a cursor for the selected row and then I want to extract a value from a particular column.

FeatureLayer featureLayer = MobileApplication.Current.Project.FindFeatureLayer("Field Crew Teams");

string whereClause = "[TEAM_ID] = 'Team A'";
QueryFilter pQFilter = new QueryFilter();
pQFilter.WhereClause = whereClause;

FeatureDataTable fDataTable = featureLayer.GetDataTable(pQFilter);
OR
FeatureDataReader fdreader = featureLayer.GetDataReader(pQFilter);



As you can see I can use either but after that I can't get access selected row and then find out the value of a particular column.

I am able to count the number of columns in my Layer, aslo able to get the index position of the column I want, but I cant figure out how to proceed from here.

Thanks,

Akhil P.
0 Kudos
AkhilParujanwala
Regular Contributor
Ok, I got even further with this but I am unable to extract the value from a particular column, it just gives me an error:

FeatureLayer featureLayer = MobileApplication.Current.Project.FindFeatureLayer("Field Crew Teams");

string user = m_signInExtension.UserID;
string whereClause = "UserID = " + "'" + user + "'";
ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog("Query String is " + whereClause); //just making sure the query is correct
QueryFilter pQFilter = new QueryFilter();
pQFilter.WhereClause = whereClause;

FeatureDataTable fDataTable = featureLayer.GetDataTable(pQFilter);
fDataTable = featureLayer.GetDataTable();

int columnNameIndex = fDataTable.Columns.IndexOf("UserID");
int featureCount = featureLayer.GetFeatureCount(pQFilter);
ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog("Feature Count = " + Convert.ToString(featureCount));  //value returned is 1, which is correct

FeatureDataReader fDataReader = featureLayer.GetDataReader(pQFilter);
ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(fDataReader.GetDataTypeName(columnNameIndex)); //this does work, it gives me "String", which is correct

fDataReader.Read; //THIS MUST BE DONE BEFORE TRYING TO READ THE TABLE, finally figured it out!
string userIs = fDataReader.GetString(columnNameIndex).ToString; //Error!     ++ Added .ToString at the end         
ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog("The user is = " + userIs); //this doesn't show up because of the error above



I have tried GetValue also but that will only return an Int. But even then, I tested it on an Int field and it still wouldn't retrieve the value from the field.
For some reason I won't run this line "string userIs = fDataReader.GetString(columnNameIndex); //Error!"

Edit: Figured it out, you must put fDataReader.Read before tryingto read the table.

----Once again thanks buddha for the queryfilter and ESRI documentation.

Thanks,

Akhil P.
0 Kudos
MelindaFrost
Frequent Contributor
Hey- glad you figured it out. But I am putting a code snippet anyway for others to see- and this shows getting the geometry and another way to get access to data values for all records in the layer.
And the only reason I know to call Read() because of working with datareaders for calls directly to database.

FeatureDataReader featDataReader = featureLayer.GetDataReader(new QueryFilter());
while (featDataReader.Read())
{
 String theName = featDataReader["Name"].ToString(); //you can use column index or column name
 Geometry m_geometry = featDataReader[featDataReader.GeometryColumnIndex] as Geometry;
}
0 Kudos