gpt4 book ai didi

c# - 如何检索部分存储在数据库中的日期列表并将其绑定(bind)在c#中的gridview中

转载 作者:行者123 更新时间:2023-11-29 18:20:05 26 4
gpt4 key购买 nike

我想在 GridView 中动态显示日期列表。日期应逐行并从数据库中检索。

以下是来自数据库的数据示例:

DSB_Date   GloveID    DSB_BalQty  DSB_Sizes
3/7/2017 ABC123 100 M
3/7/2017 ABC123 200 XL
7/7/2017 ABC123 150 L
7/7/2017 ABC123 780 M

如您所见,7 月 4 日至 7 月 6 日期间没有任何记录。但我仍然希望它们位于 GridView 中。我想要以下类型的输出:

GloveID : ABC123
Date M L XL
3/7/2017 100 0 200
4/7/2017 0 0 0
5/7/2017 0 0 0
6/7/2017 0 0 0
7/7/2017 780 150 0

它应该列出各个月份的完整日期。我没有使用任何下拉列表来填充数据。

显示 GridView 的记录是通过 Glove ID 从另一个页面检索的。假设从页面 A 单击超链接,URL 将传递手套 ID 并重定向到列出所有信息的页面 B。

下面是我用来显示尺寸和数量的 SQL 查询

 select DSB.GloveID, G.GloveCode, DSB_Month, DSB_Year, DSB_Date, 

max(case when DSB_Sizes = 'M' then DSB_BalQty else 0 end) M,
max(case when DSB_Sizes = 'L' then DSB_BalQty else 0 end) L,
max(case when DSB_Sizes = 'XL' then DSB_BalQty else 0 end) XL

from tblDailyStockBal DSB

left join tblGlove G on G.GloveID = DSB.GloveID

where DSB.GloveID = @GloveID
group by DSB.GloveID, G.GloveCode, DSB_Month, DSB_Year, DSB_Date

如何在 C# 中实现日期的目标?
我已经尝试过以下方法,但仍然没有得到我想要的。

  1. How to create a Gridview that has number of days as column based on month selection

  2. display dates row wish of select month in gridview using asp.net

最佳答案

您必须使用两个日期字符串来检查两个字符串之间的数据是否可用,例如,

SqlCommand cmd = new SqlCommand("SELECT * (or column name,column name)FROM dbo.name where Date between '" + @date1+ "' and '" +@date2 + "' order by Date desc", connection);
SqlDataAdapter sd1 = new SqlDataAdapter();
sd1.SelectCommand = cmd;
DataSet dst1 = new DataSet();
sd1.Fill(dst1, "table name");


yourgridview.DataSource = dst1.Tables[0];

这是基本思想,我希望您了解逻辑,并使用正确的安全连接,,,

关于c# - 如何检索部分存储在数据库中的日期列表并将其绑定(bind)在c#中的gridview中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46658937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com