Gridview从数据库时间戳下降毫秒

时间:2019-04-03 19:58:10

标签: asp.net vb.net datetime rowdatabound

我有一个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

0 个答案:

没有答案