Using C#, arcobjects and IQueryDef, I've been learning how to write queries to return rowsets and multiple results. I would also use ICursor and Irow to loope through each record from the cursor. This is great for multiple results but I am having trouble returning one result.
I want to run a query to return a single integer from a query. Would I need to have ICursor or IRow still? I've been looking online for examples but everything incorporates a ICursor / IRow.
I was using something along these lines:
Of course, there would be an actual table name, subfields, and a where clause there. I would use ICursor to evaluate my query def but I just want one result. So if I created a function that returned an integer with a query that just returned an integer, would I still need ICursor / IRow?
Not sure how to go about this. Not too many examples online. Any feedback on this would be greatly appreciated. Thanks in advance.
I want to run a query to return a single integer from a query. Would I need to have ICursor or IRow still? I've been looking online for examples but everything incorporates a ICursor / IRow.
I was using something along these lines:
Code:
private static List<object> GenericQuery(string sQueryColumn, string sFrom, string sWhere)
{
// connect to workspace
List<object> myObjects = new List<object>();
IQueryDef pQD = pFeatureWorkspace.CreateQueryDef();
pQD.Tables = sFrom;
pQD.SubFields = sQueryColumn;
pQD.WhereClause = sWhere;
ICursor pCursor = pQD.Evaluate();
//Loop through each of the records in the cursor
IRow pRow = pCursor.NextRow();
while (pRow != null)
{
object myObject = myObject = pRow.get_Value(lIndex);
myObjects.Add(myObject);
//Increment the cursor
pRow = pCursor.NextRow();
}
Not sure how to go about this. Not too many examples online. Any feedback on this would be greatly appreciated. Thanks in advance.