VB转换C#
Dim CN As ADODB.Connection '定义数据库的连接
Dim Rs As ADODB.Recordset
'工程---> 引用---> Microsoft ActiveX Data Object 2.x(版本号)
Private Sub Form_Load()
Set CN = New ADODB.Connection
‘连接数据库
CN.ConnectionString = "Provider=sqloledb;Data Source=pmserver;Initial Catalog=Benchmark;User Id=sa;Password=sa; "
CN.Open
Call AddTree(3)
End Sub
Private Sub AddTree(ByVal intDepth As Integer)
‘打开记录集,得到深度小于些深度的所有节点,并按深度排序
Set Rs = New ADODB.Recordset
Rs.Open "select * from tbTree where depth <= ' " & intDepth & " ' order by depth ", CN, adOpenDynamic, adLockReadOnly
Dim Xnod As Node
Do While Not Rs.EOF
If Rs.Fields( "depth ") = 0 Then
‘加入根结点
Set Xnod = TreeView1.Nodes.Add(, , "key " & Rs.Fields( "id "), Rs.Fields( "context "))
Else
‘加入子节点
Set Xnod = TreeView1.Nodes.Add( "key " & Rs.Fields( "parentid "), tvwChild, "key " & Rs.Fields( "id "), Rs.Fields( "context "))
End If
Xnod.EnsureVisible
Rs.MoveNext
Loop
Rs.Close
End Sub
这段代码转换成C#的应该怎么写呢?
数据表结构是ID,CONTEXT,DEPTH
DEPTH是深度
我就是想把数据表里的数据读取到treeview,查询出来的数据按DEPTH排序,然后依次添加第一层,第二层节点....直到第N层
谢谢啦~~~~~
------解决方案--------------------我晕,ADO,不会是VB6代码吧?
为啥不用ADO.NET?
------解决方案--------------------我帮顶