{
await QueuedTask.Run(() =>
{
try
{
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
using (Table table = geodatabase.OpenDataset<Table>("EmployeeInfo"))
{
QueryFilter queryFilter = new QueryFilter
{
WhereClause = "COSTCTRN = 'Information Technology'",
SubFields = "KNOWNAS, OFFICE, LOCATION",
PostfixClause = "ORDER BY OFFICE"
};
using (RowCursor rowCursor = table.Search(queryFilter, false))
{
while (rowCursor.MoveNext())
{
using (Row row = rowCursor.Current)
{
string location = Convert.ToString(row["LOCATION"]);
string knownAs = Convert.ToString(row["KNOWNAS"]);
}
}
}
}
}
catch (GeodatabaseFieldException fieldException)
{
// One of the fields in the where clause might not exist. There are multiple ways this can be handled:
// Handle error appropriately
}
});
}
{
await QueuedTask.Run(() =>
{
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
using (Table table = geodatabase.OpenDataset<Table>("TableWithChineseCharacters"))
{
// This will fail with many database systems that expect Latin characters by default
string incorrectWhereClause = "颜色 = '绿'";
// Correct solution is to prepend the 'National String Prefix' to the attribute value
// For example, with SQL Server this value is 'N'
// This value is obtained using the SQLSyntax class
string nationalStringPrefix = "";
SQLSyntax sqlSyntax = geodatabase.GetSQLSyntax();
nationalStringPrefix = sqlSyntax.GetSupportedStrings(SQLStringType.NationalStringPrefix).First();
// This Where clause will work
QueryFilter queryFilter = new QueryFilter()
{
WhereClause = "颜色 = " + nationalStringPrefix + "'绿'"
};
}
});
}
{
//Must be called within QueuedTask.Run()
RowCursor SearchingATable(Table table, IReadOnlyList<long> objectIDs)
{
QueryFilter queryFilter = new QueryFilter()
{
ObjectIDs = objectIDs
};
return table.Search(queryFilter);
}
}
{
// Must be called within QueuedTask.Run
void QueryFilterWithPagination(Table table, List<long> objectIDs)
{
int rowsPerBatch = 100;
int offset = 0;
// Query filter
// Some datastores support pagination only through an SQL postfix clause
QueryFilter queryFilter = new QueryFilter()
{
ObjectIDs = objectIDs,
PostfixClause = "ORDER BY OBJECTID"
};
// Fetch rows in a batch from a table
for (int index = offset; index <= objectIDs.Count; index += rowsPerBatch)
{
// Set number of rows to return from a table
queryFilter.RowCount = rowsPerBatch;
// Set positional offset to skip number of rows from a table
queryFilter.Offset = index;
using (RowCursor cursor = table.Search(queryFilter))
{
while (cursor.MoveNext())
{
using (Row row = cursor.Current)
{
Console.WriteLine(row.GetObjectID());
}
}
}
}
}
}
{
static Row FetchRowFromElement(UtilityNetwork utilityNetwork, Element element)
{
// Get the table from the element
using (Table unTable = utilityNetwork.GetTable(element.NetworkSource))
{
// Create a query filter to fetch the appropriate row
QueryFilter queryFilter = new QueryFilter()
{
ObjectIDs = new List<long>() { element.ObjectID }
};
// Fetch and return the row
using (RowCursor rowCursor = unTable.Search(queryFilter))
{
if (rowCursor.MoveNext())
{
return rowCursor.Current;
}
return null;
}
}
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)