Return Value
The gateway to access information about the SQL syntax and other functionality supported by this Datastore.
| Exception | Description |
|---|---|
| System.InvalidOperationException | No valid data store has been opened prior to invoking this operation. |
| System.NotSupportedException | The data store does not support this operation. |
| ArcGIS.Core.Data.Exceptions.GeodatabaseException | A geodatabase-related exception has occurred. |
{
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 + "'绿'"
};
}
});
}
{
await QueuedTask.Run(() =>
{
using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("C:\\Data\\LocalGovernment.gdb"))))
using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>("FacilitySite"))
{
SQLSyntax sqlSyntax = geodatabase.GetSQLSyntax();
string substringFunctionName = sqlSyntax.GetFunctionName(SQLFunction.Substring);
string upperFunctionName = sqlSyntax.GetFunctionName(SQLFunction.Upper);
string substringfunction = string.Format("{0}({1}(FCODE, 1, 6)) = 'SCHOOL'", upperFunctionName,
substringFunctionName);
QueryFilter queryFilter = new QueryFilter
{
WhereClause = substringfunction
};
using (Selection selection =
featureClass.Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal))
{
// work with the selection.
}
}
});
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)