我有c#代码,我从中得到一个异常:
" GetCurrency中针对货币代码(USD)的异常":系统。Find根据排序顺序查找行,并且没有指定排序顺序。在System.Data.Index。FindNodeByKey(Object originalKey)System.Data.Index。FindRecordByKey(对象键)"。
请查看我的代码,并告诉我为什么我得到这个异常:
public static DataView curInfoView= null;
public static string GetCurSymbol(string curCode)
{
string curSymbol = string.Empty;
if (string.IsNullOrEmpty(curCode))
return curSymbol;
try
{
curInfoView = new DataView(curInfoDataSet.Tables[0]);
if (curInfoView != null)
{
curInfoView.Sort = "CurCode Asc";
int rowIndexCurrencyInfoView = curInfoView.Find(curCode_);
if (rowIndexCurInfoView > -1)
{
// initialize large currecncy
DataRowView drCurInfo = curInfoView[rowIndexCurInfoView];
curSymbol = Convert.ToString(drCurInfo["CurSymbol"]).Trim();
}
}
}
catch (Exception ex)
{
AppLog.Log("Exception in GetCurrency For Currency Code ( " + curCode_.ToString() + ") :" + ex.ToString());
}
return curSymbol;
}
我认为Sort字符串是区分大小写的,所以应该读取
curInfoView.Sort = "CurCode ASC";
(假设数据视图中的货币代码列是CurCode)
加雷思