VB 中 DTPicker控件 字符串转换日期时间失败
发布网友
发布时间:2024-10-21 10:43
我来回答
共2个回答
热心网友
时间:2024-10-21 16:05
很笨的办法但是估计管用:
Private Sub Command1_Click()
DIM vyear as integer
DIM vmon as integer
DIM vday as integer
DIM sqlt as String
Adodc1.CommandType = adCmdText
DateSerial(DTPicker1.Value,vyear,vmon,vday)
sqlt ="select * from 入库记录 where 日期 Between Date("&vyear&","&vmon&","&vday&") and Date("
DateSerial(DTPicker2.Value,vyear,vmon,vday)
sqlt =sqlt&vyear&","&vmon&","&vday&")"
Adodc1.RecordSource = sqlt
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
A机和B机在日期转字符串的区域选项的设置不同,会导致sql语句中最终的日期字符串不一致。
最好的办法是像其它语言一样提供‘占位符’,但是adodc控件没有研究过怎么用。
比如:Java,delphi等,可以写作
cmd.text = "select * from sometab where datefiled between @date1 and @date2";
cmd.prepare;
cmd.parameters[0].asdatetime= DTPicker1.Value或者cmd.parabyname("@date1").asdatetime= DTPicker1.Value
cmd.parameters[1].asdatetime= DTPicker2.Value 或者 cmd.parabyname("@date2").asdatetime= DTPicker2.Value
热心网友
时间:2024-10-21 16:05
Adodc1.RecordSource = "select * from 入库记录 where 日期 Between #" & DTPicker1.Value & "# and #" & DTPicker2.Value & "#"
日期要用#,并且有些地方要加空格,拷贝我上面的吧