vb.net自定义面板里加载ACCESS的问题
自己做了一个停靠CAD的面板,在面板里有一个TreeView控件,在CAD里加载面板后,再执行命令"OpenData "打开ACCESS添加到TreeView,TreeView为空,中间我添加了一个MsgBox 倒是能显示读取的数据,但不能添加到TreeView里,也没错误提示,如果在面板里加一个Button,用 OpenData()下同样的代码,单击Button一切正常,TreeView能显示内容,而 OpenData()调用Button单击事件也不行,不知道是什么原因,大家帮我看看问题出在哪里Public Class MFine
<CommandMethod("OpenData")> _
Public Sub OpenData()
Dim PathString As String
Me.Open1.Title = "打开Access 文件"
Me.Open1.Filter = "Access 2003 文件(*.mdb)|*.mdb"
Me.Open1.FileName = ""
If Me.Open1.ShowDialog() = DialogResult.OK Then
PathString = Me.Open1.FileName
Dim MyConnection As New OleDbConnection()
Dim SysConnection As New OleDbConnection()
' 打开数据库连接
Dim MyConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" + PathString
' 使用OleDb .NET数据提供程序创建连接
MyConnection.ConnectionString = MyConnectionString
MyConnection.Open()
Dim comMyCommand As New OleDbCommand("Select distinct 规格FROM cgb", MyConnection)
Dim reaMyDataReader As OleDbDataReader = comMyCommand.ExecuteReader()
Dim hostName As String = System.Reflection.Assembly.GetExecutingAssembly().Location
hostName = hostName.Substring(0, hostName.LastIndexOf("\"))
Dim SysConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & hostName & "\System\Gtype.mdb"
SysConnection.ConnectionString = SysConnString
SysConnection.Open()
MsgBox(SysConnString)
Me.TreeView1.Nodes.Clear()
Me.TreeView1.Nodes.Add(PathString)
While reaMyDataReader.Read()
Dim SysCommand As New OleDbCommand("Select * From gl where 类型 ='" & reaMyDataReader(" 规格 ") & "'", SysConnection)
Dim SysReader As OleDbDataReader = SysCommand.ExecuteReader()
SysReader.Read()
If SysReader.HasRows = True Then
Dim tree_root As New TreeNode()
tree_root.Text = reaMyDataReader("规格") & " " & SysReader("类型")
MsgBox(tree_root.Text) '临时添加对话框测试是否读取到数据
Me.TreeView1.Nodes.Item(0).Nodes.Add(tree_root.Text)
End If
End While
Me.TreeView1.ExpandAll()
SysConnection.Close()
MyConnection.Close()
End If
End Sub
End Class
试试用
ResumeLayout()
Refresh()
Update()
更新TreeView 还是不行,不知道为什么同样的代码放到按钮里就可以
页:
[1]