CompareToはここでは機能しません。Linqの文字列を比較する方法
私のLINQクエリは
var result = from c in customers
where c.CustomerID.CompareTo(txtSerchId.Text) >= 0
select` c;
で、EMは例外
////// EXCEPTION ///////////
System.ArgumentException was caught
Message=Value does not fall within the expected range.
私を取得コードは次のようなものです
var result =
from c in customers
where c.CustomerID.CompareTo(txtSerchId.Text) >= 0
select c;
if (result != null)
{
IEnumerator<Customer> resultEnum = result.GetEnumerator();
while (resultEnum.MoveNext())
{
Customer c = (Customer)resultEnum.Current;
addToDataSet(Guid.NewGuid().ToString(), c);
}
ShowResult();
}
else
{
MessageBox.Show("No Customer found within criteria");
}
例外はこの行で
IEnumerator<Customer> resultEnum = result.GetEnumerator();
'txtSerchId.Text'の値が何であると予想される出力は何である私のために働きましたか?あなたは 'CustomerID'を任意の文字列と比較していますか? – Bazzz
txtSerchIdはTextFeild(WindowForm Contorl) 私はユーザーが入力した値と比較して、IDの値が小さい顧客を検索するか、ユーザーが入力した値より大きいと言うことができます。 – MBasit
、それは 'Text'ですか?そして、このテキストを「CustomerID」と比較するのにどのような意味がありますか?たぶんあなたのビジネス要件を理解していないだけかもしれません。 – Bazzz