我是一个沮丧的纽伯。我试图使用几个datetimepickers来显示DataGridView中的Access数据库的日期范围。这是我正在使用的代码:
Dim dtp1 As String = DateTimePicker1.Text
Dim dtp2 As String = DateTimePicker2.Text
Dim strCriteria, task As String
Me.Refresh()
If dtp1 = "" Then
MsgBox("Please Enter The Date Range", vbInformation, "Date Range Required")
Else
strCriteria = "([Appt Date] >= #" & dtp1 & "# And [Appt Date] <= #" & dtp2 _
& "#)"
task = "SELECT * FROM BDC1 WHERE (" & strCriteria & ") order by [Appt Date]"
End If
答案 0 :(得分:0)
尝试将您的代码更改为:
Dim dtp1 As String = DateTimePicker1.SelectedDate.Value.ToString("#yyyy/MM/dd#")
Dim dtp2 As String = DateTimePicker1.SelectedDate.Value.ToString("#yyyy/MM/dd#")
Dim con As SqlConnection ="Your connection string here"
task = "SELECT * FROM BDC1 WHERE [Appt Date] BETWEEN '" + dtp1 + "' AND '" + dtp2 + "'
order by [Appt Date]"
Dim da As SqlDataAdapter = New SqlDataAdapter(task , con)
dim dt as new datatable()
da.Fill(dt)
con.Close()
YourdatagridviewName.Datasource=dt