仅显示本月的数据 [英] Displaying data only for this month

查看:49
本文介绍了仅显示本月的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发应用程序,并且正在开发特定表格
正在连接到SQL,使用课程的存储过程也可以.

但是我在显示时遇到了问题.
我只希望它显示特定月份的商品.
它与datagridview和datetime选择器一起使用.

因此,基本上,当我选择一个月时,必须将SQL签入为同一月
并显示该月的信息.

不确定问题出在C#还是存储的过程中.

Hi all,

I''m working on an app and the specific form I''m working on
is connecting to SQL, also yes using stored procedures ofcourse.

But I have been having a problem with the displaying.
I only want it to display the items for the certain month.
It works with datagridview and datetime picker.

So basicly when I choose a month it must check in SQL to be the same month
and diplay that months info.

Not sure if the problem is in C# or stored proc.

Please can anyone help me with this??

推荐答案

我的偏好是在存储过程级别进行过滤,为什么要返回所有行,除非用户选择显示全部.

您只需将月份号作为参数传递给存储过程,然后将月份过滤器添加到WHERE子句中...我不知道从日期字段中选择月份值的sql语法,但是我知道
My preference would be to filter at the stored procedure level, why return all of your rows unless the user choses to display all.

You would simply pass the month number to the stored procedure as a param, and add the month filter to your WHERE clause... I don''t know the sql syntax to pick the month value out of a date field, but I know there is one.


从Table1中选择month(MyDate)只会给您一个月.尝试使用这种过滤.
Select month(MyDate) from Table1 gives you only the month. Try with this sort of filtering.


fcronin是正确的,您应该在存储过程中进行过滤:
fcronin is right, you should filter in your stored procedure:
... WHERE (DATEPART(month, dateField) = @monthParameter)


这篇关于仅显示本月的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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