English 中文(简体)
如何比较Linq Query的地貌
原标题:How to Compare strings in Linq Query

比较 我不在这里工作。

我要问的是:

var result = from c in customers 
             where c.CustomerID.CompareTo(txtSerchId.Text) >= 0 
             select` c;

成为例外

//////////

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();
问题回答

审判:

var query = from c in customers where c.CustomerID.Equals(txtSerchId.Text) select c;

根据你的评述,“一是比较用户的输入价值,以收集本身拥有的物品,搜索其身份少于或可说大于用户输入的客户”。

try this for "greater than":

int customerId = int.Parse(txtSerchId.Text);
if (customerId > 0)
{
   var result = from c in customers where c.CustomerID > customerId select c;
}

最新信息是,在评论中增加了更多不明确之处:

Try this:

customers.ToList().Where(c => c.CustomerID.CompareTo(txtSerchId.Text) >= 0);

通知说,由于它首先从数据库中提取了所有记录,而且根据你的细微比较,N过滤了这些记录,因此这种效率极低。 但坦率地说,我不知道有更好的办法,这样可能值得尝试。

简单:

  1. 平等:

    var result = from c in customers where c.CustomerID ==Convert.ToInt32(txtSerchId.Text) select c;

  2. For Greater : where c.CustomerID >= Convert.ToInt32 (txtSerchId.Text)

  3. 缩略语: where c.CustomerID <= Convert.ToInt32(txtSerchId.Text)

 var List = (from t in ObjCon.TableName
                            where t.GameDate.Value.CompareTo(GameDate) >= 0
                            join t1 in ObjCon.Teams on t.Home equals t1.TeamId
                            where t1.SportId == 3

* 本年度的工作





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签