I used the below function to get the single value using ArcObjects.
private string getApproverAlias(string checklistId, bool isDeleted)
{
string approverAlias = "";
var masterTable = featureWorkspace.OpenTable("TableOne");
IQueryFilter masterTableFilter = new QueryFilterClass();
masterTableFilter.SubFields = "ApproverAlias";
masterTableFilter.WhereClause = "ChecklistId = '" + checklistId + "' AND IsDeleted = " + isDeleted;
ICursor cursor = masterTable.Search(masterTableFilter, true);
IRow row = null;
while ((row = cursor.NextRow()) != null)
{
approverAlias = row.get_Value(row.Fields.FindField("ApproverAlias")).ToString();
}
return approverAlias;
}
I know from the above method the output is single value, but I'm using Cursor and Row to fetch the result.
Is it any other way to get the result without using the Cursor and Row in ArcObjects?
Something similar to ExecuteScalar in ADO.net like the below:
SqlConnection connection = new SqlConnection("Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password");
connection.Open();
SqlCommand command = new SqlCommand("SELECT ApproverAlias FROM TableOne WHERE ChecklistId = '" + checklistId + "' AND IsDeleted = " + isDeleted, connection
string approverAlias = command.ExecuteScalar();
connection.Close();