[英]Handling Optional .NET DataSource Parameters
What is the standard way to implement optional query parameters in a .NET WinForms application?在 .NET WinForms 应用程序中实现可选查询参数的标准方法是什么?
In other words, only query on a field if the value of a corresponding control is not null.也就是说,只查询对应控件的值不是null的字段。
Note: Prefer VB.NET answers (C# okay too)注意:更喜欢 VB.NET 答案(C# 也可以)
EDIT: I use a FillBy method which calls a query in my Access database.编辑:我使用 FillBy 方法在我的 Access 数据库中调用查询。 In the TableAdapter query editor, I just used WHERE (field1 =?) AND (field2 =?)...
I just can't find the "hook" to bind form controls to the table adapter query parameters and so that if a form uses the default value to not query on it.在 TableAdapter 查询编辑器中,我只是使用了WHERE (field1 =?) AND (field2 =?)...
我只是找不到将表单控件绑定到表适配器查询参数的“钩子”,因此如果一个表单使用默认值不对其进行查询。
My Access syntax is rusty, so you might have to adjust it, but you can try something like this:我的 Access 语法生锈了,所以你可能需要调整它,但你可以尝试这样的事情:
WHERE (@Field1 IS NOT NULL AND Field1 = @Field1) AND (@Field2 IS NOT NULL AND Field2 = @Field2)
You can apply LINQ Where
clause many times.您可以多次应用 LINQ Where
子句。
If you're working with a DataSet
, you can call AsEnumerable
(available since .NET 3.5) to do LINQ queries on it.如果您正在使用DataSet
,则可以调用AsEnumerable
(自 .NET 3.5 起可用)对其进行 LINQ 查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.