首页 > 解决方案 > Gridview 从数据库时间戳中删除毫秒

问题描述

我有一个Gridview显示来自数据库的记录,包括时间戳。

在这种情况RowDataBound下,我正在尝试检查时间戳以查看是否需要禁用按钮,但毫秒数被丢弃,因此我的比较无法正常工作。

如何保留从数据库到RowDataBound事件的毫秒数?

我的代码:

Dim dt As New DataTable

Using cn = New SqlConnection(ConfigurationManager.AppSettings("MyConStr"))
    cn.Open()

    Dim cmd As SqlCommand = New SqlCommand("spGetRecords", cn)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.AddWithValue("@FirstParm", FirstParm)
    cmd.Parameters.AddWithValue("@SecondParm", SecondParm)

    Using reader = cmd.ExecuteReader()
        dt.Load(reader)
    End Using
End Using

gvMyGrid.DataSource = dt
gvMyGrid.DataBind()

我的RowDataBound

Protected Sub gvMyGrid_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvMyGrid.RowDataBound
    If gvNotes.DataSource.Rows.Count > 0 Then
        Dim someTime As DateTime = "03/18/2019 08:28:09.090"
        If e.Row.Cells.Item(timestampIndex).Text = someTime 'This is never true because the cell text drops the milliseconds
            'Disable button here...
        End If
    End If
End Sub

标签: asp.netvb.netdatetimerowdatabound

解决方案


推荐阅读