Gridview dropping milliseconds from database timestamp

52 Views Asked by At

I have a Gridview that displays record from a database, including a timestamp.

In the RowDataBound event, I'm trying to check the timestamp to see if I need to disable a button but the milliseconds are dropped and so my comparisons aren't working correctly.

How do I preserve the milliseconds from the database all the way to the RowDataBound event?

My code:

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()

And my 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

There are 0 best solutions below