关于Treeview控件与ACCESS数据库联系的问题

lanzhoulamian 2005-09-28 03:28:15
我在Access数据库中建立了如下的表格:
字段名称 字段类型 字段说明
C_xmbh 数字 项目编号
C_xmmc 文本 项目名称
C_xmfjdbh 数字 项目父节点编号
C_depth 文本 深度
参考网上的一个寒暑,修改成如下的函数
Private Sub InitTree(intDepth As Integer) ‘intdepth为树的深度
Dim ReturnCode As Integer
Dim tmpsql As String
Dim Xnod As Node

tmpsql = "select * from Other_YeWu_Payout_Item_Tb where C_depth<='" & intDepth & "'" & "order by C_depth"
Set tmpRecordSet = QuerysValue(tmpsql, ReturnCode)
If ReturnCode = -1 Then

WriteErrLog "mdatabase", "Query Error", "SQL : " & tmpsql
Exit Sub
End If

If ReturnCode = 0 Then
MsgBox "未找到满足条件的纪录", vbOKOnly + vbInformation, App.Title
Exit Sub
End If

Do While Not tmpRecordSet.EOF

If CInt(tmpRecordSet.Fields("C_depth")) = 0 Then

'加入根结点

Set Xnod = TreeView1.Nodes.add(, , "key" & CStr(tmpRecordSet.Fields("C_xmbh")), Trim(tmpRecordSet.Fields("C_xmmc")))

Else

'加入子节点

Set Xnod = TreeView1.Nodes.add("key" & CStr(tmpRecordSet.Fields("C_xmfjdbh")), tvwChild, "key" & CStr(tmpRecordSet.Fields("C_xmbh")), Trim(tmpRecordSet.Fields("C_xmmc")))
End If
Xnod.EnsureVisible
tmpRecordSet.MoveNext
Loop

tmpRecordSet.Close

End Sub
当执行到添加根节点的代码时,报“实时错误13,类型不匹配”
该如何解决此问题!!!望网友能帮忙!!!
谢谢!!!
...全文
143 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
weiweiplay 2005-09-28
  • 打赏
  • 举报
回复
C_depth为空
CInt(tmpRecordSet.Fields("C_depth")) = 0 也不行
zhzhq800204 2005-09-28
  • 打赏
  • 举报
回复
用debug.print把这个字段的值显示出来看看。
bbhere 2005-09-28
  • 打赏
  • 举报
回复
gz~
lanzhoulamian 2005-09-28
  • 打赏
  • 举报
回复
C_xmbh字段里面有数据,不为空
这是我表里的数据
C_xmbh C_xmmc C_xmfjdbh C_depth
1 其他业务支出项目 0 0
2 出售品支出 1 1
3 出租支出 1 1
4 出租房屋支出 3 2
5 出租设备支出 3 2
6 邮政媒体支出 1 1
7 其他支出 1 1
Blade_hxh 2005-09-28
  • 打赏
  • 举报
回复
应该是空字段的原因
weiweiplay 2005-09-28
  • 打赏
  • 举报
回复
是不是因为你的C_xmbh字段为空?

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧