VB 中 DTPicker控件 字符串转换日期时间失败 20
在A电脑上可以使用,在B电脑上,确提示"字符串转换日期时间失败"是语句本身有问题?还是B电脑的设置和版本有问题?PrivateSubCommand1_Click()Ado...
在A电脑上可以使用,在B电脑上,确提示 "字符串转换日期时间失败"
是语句本身有问题?还是B电脑的设置和版本 有问题?
Private Sub Command1_Click()
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from 入库记录 where 日期 Between'" & DTPicker1.Value & "'and'" & DTPicker2.Value & "'"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
数据库是 SQL2008 日期字段的类型是 date 展开
是语句本身有问题?还是B电脑的设置和版本 有问题?
Private Sub Command1_Click()
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from 入库记录 where 日期 Between'" & DTPicker1.Value & "'and'" & DTPicker2.Value & "'"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
数据库是 SQL2008 日期字段的类型是 date 展开
展开全部
很笨的办法但是估计管用:
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
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
更多追问追答
追问
你说的语法是有问题的
DateSerial(DTPicker1.Value,vyear,vmon,vday)
sqlt ="select * from 入库记录 where 日期 Between Date("&vyear&","&vmon&","&vday&") and Date("
DateSerial(DTPicker2.Value,vyear,vmon,vday)
出现了如下错误:
DateSerial(DTPicker1.Value,vyear,vmon,vday) 需要=号
DateSerial(DTPicker2.Value,vyear,vmon,vday)缺少语句结束
追答
DateSerial(DTPicker2.Value,vyear,vmon,vday)
改成
vyear=year(DTPicker2.Value)
vmon=month(DTPicker2.Value)
vday=day(DTPicker2.Value)
DateSerial(DTPicker1.Value。。。。
类似改
sql语句中
Date("&vyear&","&vmon&","&vday&") 修改为 DateSerial("&vyear&","&vmon&","&vday&")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询