| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 392 人关注过本帖
标题:求助一个VB代码问题
只看楼主 加入收藏
jennysxq
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-10-6
收藏
 问题点数:0 回复次数:0 
求助一个VB代码问题
本人刚学VB不久,写了一个小程序,但运行时总是出现数据类型不匹配这样的出错信息,希望版上的各位兄弟姐妹指点一下,小女子在这里先谢谢各位了.
部分代码如下:
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strsql As String
Dim a, b As Integer
cn.Open " provider=Microsoft.Jet.OLEDB.4.0;Jet Oledb:database password=123;Data Source= " & App.Path & "\zj.mdb;Persist Security Info=False"
If Text1.Text = "" Then
strsql = "select ygid,ygname,cpid,cpprice,cpname,sum(val(cl)) as cl,sum(val(jg)) as jg from ygclxx where data>=#" & CDate(DTPicker1.Value) & "# and data<=#" & CDate(DTPicker2.Value) & "# group by ygid,ygname,ygxz,cpprice,cpname,cpid"
Else
strsql = "select ygid,ygname,cpid,cpprice,cpname,sum(val(cl)) as cl ,sum(val(jg)) as jg from ygclxx where ygid='" & Text1.Text & "' and data>=#" & CDate(DTPicker1.Value) & "# and data<=#" & CDate(DTPicker2.Value) & "# group by ygid,ygname,ygxz,cpprice,cpname,cpid"
End If
rs.Open strsql, cn, adOpenStatic, adLockBatchOptimistic
If rs.RecordCount = 0 Then
MsgBox "没有适合条件的记录"
Exit Sub
Else
MSHFlexGrid1.Rows = rs.RecordCount + 1
rs.MoveFirst
MSHFlexGrid1.Row = 0
MSHFlexGrid1.Row = MSHFlexGrid1.Row + 1
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 0) = rs.Fields("ygid")
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 1) = rs.Fields("ygname")
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2) = rs.Fields("cpid")
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 3) = rs.Fields("cpname")
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 4) = rs.Fields("cpprice")
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = rs.Fields("cl")
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 6) = Round(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 4) * MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5), 2)
rs.MoveNext
......
在两条SQL语句中加上sum(val(jg)) as jg 就出现数据类型不匹配的出错信息(未加之前运行正常),在ACCESS表中,jg(价格)字段定义为双精度的数据类型
例如:strsql = "select ygid,ygname,cpid,cpprice,cpname,sum(val(cl)) as cl,sum(val(jg)) as jg from ygclxx where data>=#" & CDate(DTPicker1.Value) & "# and data<=#" & CDate(DTPicker2.Value) & "# group by ygid,ygname,ygxz,cpprice,cpname,cpid"语句中,加上sum(val(jg)) as jg 就出现数据类型不匹配的出错信息,是什么原因呀,在线等.

[此贴子已经被作者于2007-10-6 15:03:02编辑过]

搜索更多相关主题的帖子: Microsoft Dim 代码 New 
2007-10-06 14:34
快速回复:求助一个VB代码问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011758 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved