[求组]DateTimePicker的查询问题
我在WinForm窗体上有一DataGrid,对应数据库 "入库单 ",入库时间DateTimePicker1 出库时间DateTimePicker2
入库单号 入库时间 出库时间 结帐金额
rk001 2007-5-5 2007-5-8 170
rk002 2007-5-6 2007-5-6 100
窗体在载入时,DataGrid显示如上。
我想实现当用户选择完出库时间后,即DateTimePicker2的Lostfocus,DataGrid显示处于该时间段的记录,请问怎么实现,谢谢。
[解决办法]
Private Sub DateTimePicker2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker2.LostFocus
Dim d1 As Date = Me.DateTimePicker1.Value
Dim d2 As Date = Me.DateTimePicker2.Value
Dim connectionString As String = "您的连接词 "
Dim da As New SqlClient.SqlDataAdapter( "SELECT * FROM 表名 WHERE 入库时间> = ' " & d1 & " ' AND 出库时间 <= ' " & d2 & " ' ", connectionString)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
End Sub