I’m debugging a Silverlight app, and running into an issue where an index of the array is out of bounds. I am not familiar enough with the syntax of the DataTable.Select statement, and the developer of the app is out of town for the next 10 days. The line
searchParamsTable.Select(string.Format(“TABLE = {0} AND FIELD = ‘{1}'”, tableNumbers[i], fieldName[i]))[0][“VALUE”] = wildcardedSearchString;
From the code below is where the the “index out of bounds occurs, this happens on the second iteration of “i”, when i=1. I am not quit sure what the [0][“VALUE”] represents in this situation. If someone could explain what that represents in this string I would greatly appreciate it!
if (i < 2 || country != -1)
{
if (!string.IsNullOrEmpty(wildcardedSearchString))
{
searchParamsTable.Select(string.Format("TABLE = {0} AND FIELD = '{1}'", tableNumbers[i], fieldName[i]))[0]["VALUE"] = wildcardedSearchString;
MarkRequiredParametersForSearch(searchParamsTable);
returnList = GetSearchResults(contactType, session, searchParamsTable, returnList,
(int)searchParamsTable.Select(string.Format("TABLE = {0} AND FIELD = '{1}'", tableNumbers[i], fieldName[i]))[0]["FIELDNO"]);
// Filter by authority type if necessary.
if (authorityType != AuthorityType.Unknown)
{
var results = from EntitySearchResult result in returnList
where result.SubType == (int)authorityType
select result;
if (results != null)
{
returnList = results.ToList();
}
}
}
}
DataTable.Search()returns aDataRow[], so the[0]["VALUE"]gets the value of the “VALUE” column from the first row returned bySearch.It can be re-written as:
From your code example it looks like you have a couple of places where the index out of range exception:
Searchreturns zero rows.