【发布时间】:2019-09-12 07:36:14
【问题描述】:
我有一个 SQL 公式,我计划在即将用 VB.NET 开发的 Web 程序中使用它,它将在 GridView 中显示从我的 SQL 公式获得的数据。
我的 SQL 的某个特定部分遇到了问题
select A.[Inv No], A.[Project No],
cast([Record Date] as date)as [Date], --This area is problem field
A.[Description], A.[Problem + Repair Details],
A.[Status], convert(float, A.[Accumulative Stroke])
as [Accumulative Stroke],
convert(float, A.[Preventive Stroke])
as [Preventive Stroke],
A.[PIC], A.[Measurement (OK/NG)]
from [SQL].[dbo].[MAINT_ENTRY] A
left join (select [Inv No], max(Date +' '+ Time) as [Record Date]
from [SQL].[dbo].[MAINT_ENTRY]
group by [Inv No]) B
on A.[Inv No] = B.[Inv No]
where [Record Date] = Date +' '+ Time and
[Problem + Repair Details] <> '""'
Order by A.[Status], A.[Inv No], A.[Date]desc
[Record Date] 是一个将Date 和Time 列合并为一个合并列的列,以便我获得最新数据以显示在我的程序中。这两个字段都需要采用datetime 格式才能加入。
我希望 GridView 仅在 Record Date 中显示日期,因为它在 datetime 中,我尝试使用 CAST 将格式更改为 date。
虽然它在我模拟结果的 SQL Management Studio 中显示了正确的结果,但它似乎不想在 VB.Net 中发挥出色,因为我得到的结果仍然使用datetime 格式。它会删除时间数据,但仍保留时间格式。
22/4/2019 08:45:00 AM ---> 22/4/2019 12:00:00 AM
这似乎是什么问题造成的?
【问题讨论】:
-
您在 SQL 中使用的类型并不重要,因为 .NET 只有包含日期和时间的
DateTime类型。尽管 VB 有Date类型,但它只是DateTime的别名。如果您不希望显示时间,则需要在 UI 中显示数据时在格式中指定该时间。如果您想在GridView控件中执行此操作,则要做的就是研究如何在该控件中指定格式。
标签: sql asp.net vb.net gridview webforms