CompareTo is not working here for me.
My linq query is
var result = from c in customers
where c.CustomerID.CompareTo(txtSerchId.Text) >= 0
select` c;
and em getting an exception
//////EXCEPTION///////////
System.ArgumentException was caught
Message=Value does not fall within the expected range.
My code is something like this
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");
}
exception is at this line
IEnumerator<Customer> resultEnum = result.GetEnumerator();
Equals() method is a method of String class. This method takes two strings to be compared as parameters.
ToUpper() Method in C# If we want to compare two string variables by ignoring cases, we can convert both strings to upper-case characters and then compare them. The String. ToUpper() method converts a string to uppercase characters.
try this :
var query = from c in customers where c.CustomerID.Equals(txtSerchId.Text) select c;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With