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(); }
private static int GenericQuery(string sQueryColumn, string sFrom, string sWhere) { ICursor pCursor = null; try { IQueryDef pQD = pFeatureWorkspace.CreateQueryDef(); pQD.Tables = sFrom; pQD.SubFields = sQueryColumn; pQD.WhereClause = sWhere; pCursor = pQD.Evaluate(); //Get the first Row IRow pRow = pCursor.NextRow(); //Get your integer value if (pRow != null) { object myObject = pRow.get_Value(lIndex); if (myObject != null) { return Convert.ToInt32(myObject); } } return -1;//Default value } catch (Exception) { return -1; } finally { if (pCursor!=null) { Marshal.FinalReleaseComObject(pCursor); } } }
public static int FirstQuery() { int _val = 0; ICursor _pCursor = null; try { IFeatureWorkspace _pfeatureWorkspace = Utilities.connect(); /* * Query below will iterate through several rows of returned data from query * I need a query to return a single value */ IQueryDef _pdq = _pfeatureWorkspace.CreateQueryDef(); _pdq.Tables = PersonsTable.TableName; _pdq.SubFields = PersonsTable.PERSON_ID; _pdq.WhereClause = PersonsTable.FIRST_NAME = "JAMARI"; _pCursor = _pdq.Evaluate(); int lIndex = _pCursor.FindField(_pdq.SubFields); IRow _pRow = _pCursor.NextRow(); if (_pRow != null) { object _myObject = _pRow.get_Value(lIndex); if (_myObject != null) { _val = Convert.ToInt32(_myObject); return _val; } } return _val; } catch (Exception) { return -1; } finally { if (_pCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(_pCursor); } } }
protected override void OnClick() { int _queryVal = 0; MessageBox.Show("Jamari was here"); _queryVal = BasicQuery.FirstQuery(); MessageBox.Show("Query result is: " + _queryVal); }
_pdq.WhereClause = PersonsTable.FIRST_NAME = "JAMARI"
_pdq.WhereClause = PersonsTable.FIRST_NAME + " = 'JAMARI'";