求助vb高手
我现在在做一个vb的毕业设计,但是在使用查询语句的时候总是显示标准表达式中数据类型不匹配的错误,我找不出原因,现在有没有哪位高手可以帮帮我啊?
G1.Text = Left(DTP1, 4) & Right(Left(DTP1, 7), 2) & Right(DTP1, 2) & Left(DTM1, 2) & Left(Right(DTM1, 5), 2)
G2.Text = Left(DTP2, 4) & Right(Left(DTP2, 7), 2) & Right(DTP2, 2) & Left(DTM2, 2) & Left(Right(DTM2, 5), 2)
Data1.RecordSource = "select * from djys where djys.BZ >" & Val(G1.Text) & "AND djys.BZ<" & Val(G2.Text) & " order by 凭证号码"
Data1.Refresh
Data2.RecordSource = "select count(*) as ddd,sum(应收宿费)as 应收宿费1 ,sum(预收金额)as 预收汇总 from djys where djys.BZ between'" & Val(G1.Text) & "' AND '" & Val(G2.Text) & "'" ' and djys.标志 like " + Chr(34) + "*" + Chr(34) + ""
Data2.Refresh
这个是代码。数据类型都是数值和货币。我实在看不出是哪里错了。请求高手帮助。谢谢啊!
[解决办法]
检查你定义的那些变量.
比如,如果DTP1为数值型的话,那就不能对它用left之类的函数.
[解决办法]
设断点看看g1,g2里面到底是什么,是不是Date阿
再说
Data2.RecordSource = "select count(*) as ddd,sum(应收宿费)as 应收宿费1 ,sum(预收金额)as 预收汇总 from djys where djys.BZ between'" & Val(G1.Text) & "' AND '" & Val(G2.Text) & "'" ' and djys.标志 like " + Chr(34) + "*" + Chr(34) + ""
红色的部分错了阿
要不就是这样
Data2.RecordSource = "select count(*) as ddd,sum(应收宿费)as 应收宿费1 ,sum(预收金额)as 预收汇总 from djys where djys.BZ between'" & Val(G1.Text) & "' AND '" & Val(G2.Text) & "' and djys.标志 like " + Chr(34) + "*" + Chr(34) + ""
要不就是
Data2.RecordSource = "select count(*) as ddd,sum(应收宿费)as 应收宿费1 ,sum(预收金额)as 预收汇总 from djys where djys.BZ between" & Val(G1.Text) & " AND " & Val(G2.Text) & " and djys.标志 like " + Chr(34) + "*" + Chr(34) + ""
[解决办法]
看看djys.BZ 这个字段在数据库里面是什么类型,如果是字符或日期型,需要加单引号;
条件要以和作为区间, 用having语句. where……group by……having (sum(x)>0);