[英]Access Database select more than one row in c#
I have been following this site for basic Access database implementation in C# 我一直在关注此站点以获取C#中的基本Access数据库实现
http://www.homeandlearn.co.uk/csharp/csharp_s12p12.html http://www.homeandlearn.co.uk/csharp/csharp_s12p12.html
I want to search more than one row. 我想搜索多行。 This code works for one row. 此代码适用于一行。
string searchFor = txtFurniture.Text;
returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "'");
How do I add in additional rows to check? 如何添加其他行以进行检查? I have tried something like 我尝试过类似的东西
returnedRows = ds1.Tables["Furniture"].Select("Finish='" + "Style='" + searchFor + "'");
but this fails. 但这失败了。
you need to add and condition 你需要添加和条件
returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor +
"' and Style='" + searchFor + "'");
In addition you can check this answer might help you to understand easily : Datatable select with multiple conditions 此外,您可以查看此答案可能有助于您轻松理解: 数据表选择多个条件
You mean an additional field to check. 你的意思是要检查一个额外的字段。
Make a condition that looks like this: 制作一个如下所示的条件:
Finish='something' and Style='something'
using: 使用:
returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "' and Style='" + searchFor + "'");
As referenced in the documentation for the DataTable.Select method , the documentation for the DataColumn.Expression property describes the syntax to be used with the filterExpression
parameter. 正如DataTable.Select方法的文档中所引用的那样, DataColumn.Expression属性的文档描述了与filterExpression
参数一起使用的语法。 In your case, use And
to create a compound expression with your two conditions: 在您的情况下,使用And
创建具有两个条件的复合表达式:
returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "' And Style='" + searchFor2 + "'");
...or more readably... ......或更可读......
string filterExpression = string.Format("Finish='{0}' And Style='{1}'", searchFor, searchFor2);
DataRow[] returnedRows = ds1.Tables["Furniture"].Select(filterExpression);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.