这是一个解决方案(由我和谷歌搜索)。
这是简单的方法。
In DataGridView
- >Add Query...
- >Query Builder..
。 在Date
列(或任何你有)Filter
单元格写:BETWEEN @ Date1 AND @ Date2。 单击确定,然后再次单击确定。
在Form
区域您现在看到一个带有2个文本框的Form标题区下的新行。首先是Date1
,第二个是Date2
。文本框区域后是一个名为Fillby
的按钮。 将Date1,Date2和Fillby的名称从属性更改为任何您喜欢的内容,例如从: - 到: - 搜索。
要做到这一点的另一种方法比较困难。
首先把2 buttons
和2 Timepickers
在Form
地区。
Next in DataGridView
- >Add Query...
- >Query Builder..
。 在Date
列(或任何你有)Filter
单元格写:BETWEEN @ Date1 AND @ Date2。 单击确定,然后再次单击确定。
在Form
代码视图区域粘贴第一个按钮代码(按钮1):
Public Function GetFromDate(ByVal value As DateTime) As DateTime
Return New DateTime(value.Year, value.Month, value.Day, 0, 0, 0, 0)
End Function
Public Function GetToDate(ByVal value As DateTime) As DateTime
Return New DateTime(value.Year, value.Month, value.Day, 23, 59, 59, 999)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim BeginningDateTime As Date = GetFromDate(DateTimePicker1.Value)
Dim EndingDateTime As Date = GetToDate(DateTimePicker2.Value)
Try
Me.Table2TableAdapter.FillBy(Me.Database1DataSet1.Table2, New System.Nullable(Of Date)(CType(BeginningDateTime, Date)), New System.Nullable(Of Date)(CType(EndingDateTime, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
而接下来这段代码的第二个按钮(Button2的):
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Table2TableAdapter.Fill(Me.Database1DataSet1.Table2)
End Sub
你必须改变:
1)Table2TableAdapter
什么是您的表适配器。
2)Database1DataSet1
什么是您的数据库数据集。
3)Table2
在什么是你的表。
代码FillBy
,DateTimePicker1
,DateTimePicker2
如果您的数据库有差异,则必须更改。
有关代码的更多信息,您可以从查询构建器中看到代码。 它看起来像:
Private Sub FillByToolStripButton_Click...
在那里,你可以找到所有信息的更改上面的代码。
毕竟你可以删除这段代码(Private Sub FillByToolStripButton_Click...
)。
这就是我所找到的,我解决了我在两个日期之间搜索的问题。