Hi Richard,I connect to Oracle to perform SQL, not via SDE or using layer in the map. I don't think ESRI support max or min function in attribute query. It seems you only can define the WHERE clause but not the SELECT part.Here is the code I use to get the X, Y value. The where clause in my SQL is the same as the definition query in the point layer.
Dim SQL As String
Dim WhereClause As String
WhereClause = " WHERE NCR_ID IN (" + ptsStr + ")"
SQL = "SELECT MIN(X) AS MIN_X, MIN(Y) AS MIN_Y, MAX(X) AS MAX_X, MAX(Y) AS MAX_Y FROM TBL_POINTS" + WhereClause
Dim cmd As New OracleCommand(SQL, cn)
cmd.Connection.Open()
Dim rdr As OracleDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While rdr.Read
minx = rdr("MIN_X")
miny = rdr("MIN_Y")
maxx = rdr("MAX_X")
maxy = rdr("MAX_Y")
End While
rdr.Close()
cmd.Dispose()
'Set up the envelope for the new map extent
Dim pEnv As IEnvelope = New Envelope
pEnv.PutCoords(minx, miny, maxx, maxy)
pEnv.Expand(1.1, 1.1, True)
pMxDoc.ActivatedView.Extent = pEnv
'Refresh the map
pMxDoc.ActivatedView.Refresh()
To answer you question, I wanna zoom to the layer which has a definition query on it, so extent should be the overall extent of the valid features only. I don't know why, but the "zoom to layer" function works in my ArcMap desktop, when I right click on the layer (with definition query) and click on "Zoom to Layer", the map zooms to the valid extent (not the whole extent of the layer). And when it comes to VB.NET, that zoom to layer function doesn't behave that way any more, it zooms to the extent of the entire layer. I am a bit confused actually.