【发布时间】:2014-09-28 20:56:27
【问题描述】:
我的要求是让用户从 DateTimePicker 中选择一个日期,然后 GataGridView 将检索并显示与 DateTimePicker 中的值匹配的信息。
Private Sub DateTimePicker3_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker3.ValueChanged
dailyloadglog()
End Sub
.
Public Sub dailyloadglog()
Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & aaa & "';Persist Security Info=True;")
Try
Dim OOL As String = "SELECT Glogtbl.DIN, Glogtbl.clock, Int([clock]) AS JustDate, [clock]-Int([clock]) AS JustTime FROM Glogtbl WHERE JustDate = " & DateTimePicker3.Value.ToShortDateString & ""
Dim cmd As New OleDbCommand
Dim odpt As New OleDbDataAdapter
Dim tbl As New DataTable
With cmd
.CommandText = OOL
.Connection = connection
End With
With odpt
.SelectCommand = cmd
.Fill(tbl)
End With
DataGridView4.Rows.Clear()
For i = 0 To tbl.Rows.Count - 1
With DataGridView4
.Rows.Add(tbl.Rows(i)("DIN"), tbl.Rows(i)("clock"), tbl.Rows(i)("JustDate"), tbl.Rows(i)("JustTime"))
End With
Next
connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
ex.exception 给了我这个:
当我尝试检索所有日期/时间列并显示结果时:
Dim OOL As String = "SELECT Glogtbl.DIN, Glogtbl.clock, Int([clock]) AS JustDate, [clock]-Int([clock]) AS JustTime FROM Glogtbl"
JustDate 值仍保留格式长日期时间值。因此,与 datetimepicker.value 进行比较的值总是错误的。最终什么都没有检索到!!!
谁能指导我这个?!
【问题讨论】: