选择时间段 表加载相应数据
开始日期 2012-2-1(DTpicker1) 结束日期 2012-2-29(DTpicker2) 确定(command1)
DataGrid控件里的内容如下
ID 日期
1 2012-1-1
2 2012-1-2
3 2012-1-3
........
............
99 2012-3-5
用的是access数据库 有个“Tb_工厂日历”表 DataGrid里面加载的就是这个表里的数据
我想让开始日期选择2012-2-1 然后结束日期选择2012-2-29 然后DataGrid下面的加载页变成 这个时间段的数据
谁能帮我解决下吗
[解决办法]
在LOAD的时候给这二个控件赋初值或直接在控件的VALUE上填入你要的值,DataGrid下面变成这个时间段的直接循环插入就好了。以下是对这个时间段进行循环的代码,供你参考,希望能帮你到。
Dim dt1 As DateTime = DateTime.Parse(DateTimePicker1.Text)
Dim dt2 As DateTime = DateTime.Parse(DateTimePicker2.Text)
Dim i As Integer = 0
While (DateTime.Compare(dt1.AddDays(i), dt2) <= 0)
MsgBox(dt1.AddDays(i))
i = i + 1
End While
[解决办法]
Dim dt1 As DateTime = format(DateTimePicker1.value,"yyyy-M-d")
Dim dt2 As DateTime = fromat(DateTimePicker2.Text,"yyyy-M-d")
dim sql as string ="select * from Tb_工厂日历 where 日期>='" & dt1 & "' and 日期<='" & dt2 & "' order by id"
dim adapter1 as oledb.oledbadpater=new oledb.oledbadpater(sql,new oledb.oledbconnection(conncetionString)) 'conncetionString为数据库连接字符串
dim dataS as new dataset
adapter1.fill(dataS)
DataGrid.datasouce=dataS.tables(0)