如何根据使用C#在文本框中输入的日期在gridview中显示数据 [英] How can I display the data in gridview based on the date entered in textbox using C#

查看:115
本文介绍了如何根据使用C#在文本框中输入的日期在gridview中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有以下栏目



 Sno状态FromDate ToDate 
1待定02/20/2017 2017/02/26
2暂停01/10/2017 01/25/2017
3已完成02/21/2017 02/26/2017
4已完成02/22/2017 02 / 28/2017
5暂挂01/15/2017 01/30/2017
6 Pending 01/20/2017 02/22/2017





如果我们在文本框中输入02/25/2017并点击获取,那么我需要在gridview中显示以下记录的数量为



< pre lang =text>待定保留已完成
1 0 2





暂挂中的计数1是数据库中的第一条记录因为它来自和迄今为止b在02/25/2017范围内,完成中的计数2是数据库中的第3和第4条记录,因为它在02/25/2017范围之间和之间有,并且保持计数为0,因为文本框中给出的日期不是包含在hold.how我可以这样做任何人都可以帮助我,因为我是这个新手



我尝试过:



如何使用c#代码或查询

解决方案

这是SQL中的这个想法你执行时可能会遇到一些错误,因为下面的查询没有被检查过。但是这个想法介于条件和内部联系之间





 SELECT S.Status,C.cnt 
FROM YourTable S
INNER JOIN(选择状态,计数(状态)为cnt
FROM YourTable
GROUP BY状态)C ON S.Status = C.Status其中CONVERT(VARCHAR(10),输入日期,101)在CONVERT(VARCHAR(10),S.FromDate,101)和CONVERT(VARCHAR(10),S.ToDate,10之间) 1)





在上面的查询

 inputdate 

是你从你传递的日期c#将存储过程的代码作为输入参数。



从sql获取此数据后将其提供给数据表或列出您使用的数据然后绑定到数据网格/ gridview的。


I have below columns in my database as

Sno                Status              FromDate              ToDate
1                  Pending             02/20/2017            02/26/2017
2                  Hold                01/10/2017            01/25/2017
3                  Completed           02/21/2017            02/26/2017
4                  Completed           02/22/2017            02/28/2017
5                  Hold                01/15/2017            01/30/2017
6                  Pending             01/20/2017            02/22/2017



If we enter 02/25/2017 in textbox and click get then i need to show count of below records in gridview as

Pending              Hold                Completed
  1                    0                     2



Count 1 in pending is the first record in database as it has from and to date between the range 02/25/2017, Count 2 in Completed is the 3rd and 4th record in database as it has from and to date between the range 02/25/2017 and hold has count 0 as the date given in text box does not contain in hold.how can i do this can anyone help me out as i am new to this

What I have tried:

How can i do this either with c# code or with query

解决方案

This is the idea below in SQL.You may get some error while executing because this below query was not checked.But the idea lies between where condition and Inner join


SELECT S.Status,  C.cnt
  FROM YourTable S
       INNER JOIN (SELECT Status, count(Status) as cnt
                     FROM YourTable
                    GROUP BY Status) C ON S.Status= C.Status where CONVERT(VARCHAR(10), inputdate, 101)between CONVERT(VARCHAR(10),S.FromDate,101) and CONVERT(VARCHAR(10),S.ToDate,101) 



In above query

inputdate

is the date that you pass from your c# code to the stored procedure as input parameter.

After getting this data from sql feed it to the data table or list what ever you use and then bind to the data grid/gridview.


这篇关于如何根据使用C#在文本框中输入的日期在gridview中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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