| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1127 人关注过本帖, 1 人收藏
标题:请教下各位大侠VB treeview 的关键字报错咋办?谢谢
取消只看楼主 加入收藏
coffecat1119
Rank: 2
等 级:论坛游民
帖 子:166
专家分:84
注 册:2008-6-19
结帖率:96.88%
收藏(1)
 问题点数:0 回复次数:3 
请教下各位大侠VB treeview 的关键字报错咋办?谢谢
Call con

我的代码如下,我想要实现数据库每添加一条记录treeview 的树结构也同步更新记录
以下代码我放在form_load 事件里完全正常,但是放在添加完数据库记录之后却提示关键字不唯一或者是无效关键字,不知道是什么缘故,请指教,谢谢

------------------------代码如下————————————————————
Dim key, text As String
  Dim nod As Node
  key = "同学名单"
 text = "同学名单"
 With main.TreeView1
  Set node1 = .Nodes.add(, , key, text, 1)
  End With
  asing = "select * from [kf]"
 Rs.Open asing, Cnn, 3, 3



Do While Not Rs.EOF
key = Trim(Rs.Fields("name").Value)

text = Trim(Rs.Fields("name").Value)
With main.TreeView1
Set node2 = .Nodes.add(node1.Index, tvwChild, key, text, 1)
End With

Rs.MoveNext
Loop '循环语句
Rs.Close '循环完后 就关闭记录集
Cnn.Close
  
With main.TreeView1
.HotTracking = True
For i = 1 To .Nodes.Count

.Nodes(i).Expanded = False
Next i

End With

Set Rs = Nothing
Set Cnn = Nothing










搜索更多相关主题的帖子: 关键字 记录 
2011-10-26 20:23
coffecat1119
Rank: 2
等 级:论坛游民
帖 子:166
专家分:84
注 册:2008-6-19
收藏
得分:0 
哎,令人遗憾,居然没人理我
2011-10-26 22:27
coffecat1119
Rank: 2
等 级:论坛游民
帖 子:166
专家分:84
注 册:2008-6-19
收藏
得分:0 
我搞定了,完整代码如下:


Private Sub tianjia_Click()
If Trim(add.xm.text) = Empty Then
MsgBox "客户姓名没有填写!", vbInformation, "系统提示"
add.xm.SetFocus
Exit Sub
End If
If Len(add.xm.text) > 20 Then
MsgBox "客户姓名不能大于20位字符!", vbInformation, "系统提示"
add.xm.SetFocus
Exit Sub
End If
If Trim(add.dh.text) = Empty Then
MsgBox "客户联系电话没有填写!", vbInformation, "系统提示"
add.dh.SetFocus
Exit Sub
End If
 If Not IsNumeric(add.dh.text) Then
 MsgBox "联系电话应该是数字吧,请重输入!", vbInformation, "系统提示"
 add.dh.SetFocus
 Exit Sub
 End If
 
If Len(add.dh.text) > 11 Then

MsgBox "手机号码也只有11位哦,请重新输入!", vbInformation, "系统提示"
add.dh.SetFocus
Exit Sub
End If



If Trim() <> Empty Then

If Not IsNumeric() Then
 MsgBox "备用号码请输入数字!", vbInformation, "系统提示"
 
 Exit Sub
 End If
 End If
 
 
If Len() > 11 Then
MsgBox "手机号码也只有11位哦,请重新输入!", vbInformation, "系统提示"

Exit Sub
End If
If Trim(add.zz.text) = Empty Then
MsgBox "客户家庭住址没有填写!", vbInformation, "系统提示"
add.zz.SetFocus
Exit Sub
End If
If Len(add.zz.text) > 30 Then
MsgBox "输入的客户家庭住址不得超过30个字符", vbInformation, "系统提示"
add.zz.SetFocus
Exit Sub
End If
If Trim() = Empty Then
MsgBox "请选择适当的机型分类!", vbInformation, "系统提示"

Exit Sub
End If


If Len() > 10 Then
MsgBox "输入机型分类不能超过10个字符!", vbInformation, "系统提示"

Exit Sub
End If
If Trim() = Empty Then
MsgBox "请选择适合的显示屏品牌!", vbInformation, "系统提示"

Exit Sub
End If
If Len() > 10 Then

MsgBox "输入显示屏品牌不能超过10个字符!", vbInformation, "系统提示"

Exit Sub
End If
If Len() > 15 Then
MsgBox "输入显示屏型号不能超过15个字符!", vbInformation, "系统提示"

Exit Sub
End If
If Trim(add.psn.text) = Empty Then
MsgBox "显示屏序列号/SN编码不能为空!", vbInformation, "系统提示"
add.psn.SetFocus
Exit Sub
If Trim() = Empty Then
MsgBox "请选择适合的显示屏保点情况!", vbInformation, "系统提示"

Exit Sub
End If
End If
If Trim(add.jp.text) = Empty Then
MsgBox "新主机品牌不能为空!", vbInformation, "系统提示"
add.jp.SetFocus
Exit Sub
End If
If Trim(add.jx.text) = Empty Then
MsgBox "请输入新主机型号!", vbInformation, "系统提示"
add.jx.SetFocus
Exit Sub
End If
If Trim(add.jsn.text) = Empty Then
MsgBox "电脑主机序列号/SN编码不能为空!", vbInformation, "系统提示"
add.jsn.SetFocus
Exit Sub
End If
If Trim() = Empty Then
MsgBox "请选择预保修模式!", vbInformation, "系统提示"

Exit Sub
End If
If Trim(add.ldy.text) = Empty Then
MsgBox "系统录单员姓名不能为空!", vbInformation, "系统提示"
add.ldy.SetFocus
Exit Sub
End If

If Trim(add.shr.text) = Empty Then
MsgBox "系统审核员姓名不能为空!", vbInformation, "系统提示"
add.shr.SetFocus
Exit Sub
End If
Call con
Rs.Open "select * from [kf]", Cnn, 3, 3

Do While Not Rs.EOF
If Trim(add.xm.text) = Rs.Fields("name") And Trim(add.jsn.text) = Rs.Fields("pcsn") Then

MsgBox "要添加的客户已存在,请勿重复添加!", vbInformation, "系统提示!"
add.tianjia.Enabled = False
add.xiugai.Enabled = True
add.shanchu.Enabled = False
add.beifen.Enabled = False
add.huifu.Enabled = False
Rs.Close
Cnn.Close
Exit Sub
End If
Rs.MoveNext
Loop
Rs.AddNew
Rs.Fields("name") = Trim(add.xm.text)
Rs.Fields("tel") = Val(add.dh.text)
Rs.Fields("phone") = Val()
Rs.Fields("addr") = Trim(add.zz.text)
Rs.Fields("lei") = Trim()
Rs.Fields("xpai") = Trim()
Rs.Fields("xxing") = Trim(add.px.text)
Rs.Fields("xsn") = Trim(add.psn.text)
Rs.Fields("xdate") = DT1.Value
Rs.Fields("xbx") = DT2.Value
Rs.Fields("bd") = Trim()
Rs.Fields("zpai") = Trim(add.jp.text)
Rs.Fields("xing") = Trim(add.jx.text)
Rs.Fields("pcsn") = Trim(add.jsn.text)
Rs.Fields("fs") = Trim()
Rs.Fields("sdate") = DT3.Value
Rs.Fields("bdate") = DT4.Value
Rs.Fields("luser") = Trim(add.ldy.text)
Rs.Fields("lchk") = Trim(add.shr.text)





Rs.Update


MsgBox "客户信息添加成功", vbCritical, "系统提示!"

Rs.Close
Cnn.Close
Set Rs = Nothing
Set Cnn = Nothing

Unload add
With main.ListView1
.ListItems.Clear
End With



Call tree_change


End Sub







Public Sub tree_change()
Call con


Dim key, text As String
  Dim nod As Node

 With main.TreeView1
 .Nodes.Clear
  Set node1 = .Nodes.add(, , "客户名单", "客户名单", 1)
  End With
  asing = "select * from [kf]"
 Rs.Open asing, Cnn, 3, 3



Do While Not Rs.EOF


text = Trim(Rs.Fields("name").Value)
With main.TreeView1

Set node2 = .Nodes.add("客户名单", tvwChild, , text, 1)



End With

Rs.MoveNext
Loop '循环语句
Rs.Close '循环完后 就关闭记录集
Cnn.Close
  
With main.TreeView1
.HotTracking = True
For i = 1 To .Nodes.Count

.Nodes(i).Expanded = False
Next i

End With

Set Rs = Nothing
Set Cnn = Nothing


2011-10-26 23:13
coffecat1119
Rank: 2
等 级:论坛游民
帖 子:166
专家分:84
注 册:2008-6-19
收藏
得分:0 
解决方案:修正 relative  的值  ,再重载入TREEVIEW绑定的数据前先用treeview1.nodes.clear 清空原有的数据
2011-10-26 23:16
快速回复:请教下各位大侠VB treeview 的关键字报错咋办?谢谢
数据加载中...
 
   



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

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