如何从具有许多过滤器选项的数据库中选择数据? [英] How to select data from database with many filter options?

查看:40
本文介绍了如何从具有许多过滤器选项的数据库中选择数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建连接到数据库的 C# winforms 应用程序.因为我在数据库中有很多记录,所以我想在 sql 端过滤数据(过滤器必须有很多没有开始/结束日期的选项).

I am creating C# winforms application, which connects to the Database. Because I have a many records in database, I want to filter data on sql side (Filter must have many options without start/end date).

实现这一目标的最佳方法是什么?

What is a best way to achive this?

我知道我可以使用 BindingSource 进行过滤,但我认为不推荐这样做,因为在这种情况下我必须从数据库中选择所有数据.

I know I can use BindingSource for filtering, but I think It is not recomended, because in this case I must select all data from database.

附言对不起,我的英语不好.

p.s. Sorry for my poor English.

推荐答案

您应该始终更喜欢过滤数据库上的数据,而不是将不需要的数据带入您的应用程序并使用代码进行过滤.

You should always prefer filtering data on database instead of bringing unwanted data to your application and filtering with code.

例如

string query = "SELECT * FROM MyTable ";

在下面的字符串中添加一个 WHERE 子句和成对的 column = value 或 column = expression

In the string below you add a WHERE clause and pairs of column = value or column = expression

 string query = "SELECT * FROM MyTable WHERE column1=somevalue AND column2 > somevalue AND ...";

这篇关于如何从具有许多过滤器选项的数据库中选择数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆