Access 数据库在 C# 中选择多行

发布于 2024-12-19 03:52:12 字数 519 浏览 0 评论 0原文

我一直在关注这个网站,以 C#

http://www.homeandlearn 实现基本的 Access 数据库。 co.uk/csharp/csharp_s12p12.html

我想搜索不止一行。此代码适用于一行。

string searchFor = txtFurniture.Text;
returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "'");

如何添加额外的行进行检查?我尝试过类似的方法,

returnedRows = ds1.Tables["Furniture"].Select("Finish='" + "Style='" + searchFor + "'");

但失败了。

I have been following this site for basic Access database implementation in C#

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人生戏 2024-12-26 03:52:13

正如DataTable.Select 方法的文档中所引用的,DataColumn.Expression 属性的文档 描述了与filterExpression 参数。在您的情况下,使用 And 创建具有两个条件的复合表达式:

returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "' And Style='" + searchFor2 + "'");

...或更易读...

string filterExpression = string.Format("Finish='{0}' And Style='{1}'", searchFor, searchFor2);
DataRow[] returnedRows = ds1.Tables["Furniture"].Select(filterExpression);

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. In your case, use And to create a compound expression with your two conditions:

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);
﹂绝世的画 2024-12-26 03:52:12

您需要添加和条件

returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor +
                                           "' and Style='" + searchFor + "'");

另外您可以检查这个答案可能会帮助您轻松理解: Datatable select具有多个条件

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

謸气贵蔟 2024-12-26 03:52:12

您的意思是要检查的附加字段。

创建一个如下所示的条件:

Finish='something' and Style='something'

使用:

returnedRows = ds1.Tables["Furniture"].Select("Finish='" + searchFor + "' and Style='" + searchFor + "'");

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 + "'");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文