尊敬的先生, 我试图通过下面的脚本按月日历过滤数据视图,但我没有得到行的信息。我在这个剧本中做的错误是什么?
If Me.myDataSet.myTable.Rows.Count > 0 Then
Dim myDataView As New DataView
myDataView.Table = Me.myDataSet.myTable
Dim myDate As String = String.Format("[vstime] = '{0:M/dd/yyyy}' ", MonthCalendar1.SelectionRange.Start.Date)
myDataView.RowFilter = String.Format(myDate)
End If
你的忠实
Murulimadhav
答案 0 :(得分:0)
好的,我通过这个例子解决了它 How to use BindingSource.Filter for a Date in visual basic 2012? 还是有比这更简单的解决方案?
Public myFilterDate As DateTime
Public Sub myDayFilter(ByVal myFilterDate)
If Me.myDataSet.myTable.Rows.Count > 0 Then
myFilterDate = MonthCalendar1.SelectionRange.Start.Date
Dim dateFrom As DateTime = myFilterDate.Date
Dim dateTo As DateTime = dateFrom.AddDays(1).Subtract(New TimeSpan(1))
Dim filterBuilder As New StringBuilder()
Dim filterFormat As String = "vstime {0} #{1:yyyy/MM/dd HH:mm:ss}#"
With filterBuilder
.AppendFormat(filterFormat, ">=", dateFrom)
.Append(" AND ")
.AppendFormat(filterFormat, "<=", dateTo)
End With
Me.myBindingSource1.Filter = filterBuilder.ToString()
End If
End Sub
Private Sub MonthCalendar1_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
myDayFilter(myFilterDate)
End Sub
感谢你
用于书信结尾)你忠实的
Murulimadhav