任何人都可以将我的VB代码写入C# [英] Can anyone write my VB code to C#

查看:64
本文介绍了任何人都可以将我的VB代码写入C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

i有一个VB代码从数据库填充树视图。我的代码是

hi all
i have a VB code to populate tree view from database.my code is

If rec2.EOF = False And rec2.BOF = False Then
    Do While rec2.EOF = False
        If dept1 <> rec2.Fields(0) Then
            d1 = d1 + 1
            TreeView1.Nodes.Add , , "*" & CStr(rec2.Fields(0)) & "*", rec2.Fields(0)
            If UCase(rec2.Fields(2)) = "ONE" Then
                TreeView1.Nodes.Add "*" & rec2.Fields(0) & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 3) & " " & rec2.Fields(4)
                one1 = rec2.Fields(3)
            ElseIf UCase(rec2.Fields(2)) = "TWO" Then
                TreeView1.Nodes.Add "*" & one1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 5) & " " & rec2.Fields(4)
                two1 = rec2.Fields(3)
            ElseIf UCase(rec2.Fields(2)) = "THREE" Then
                TreeView1.Nodes.Add "*" & two1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 7) & " " & rec2.Fields(4)
                three1 = rec2.Fields(3)
            ElseIf UCase(rec2.Fields(2)) = "FOUR" Then
                TreeView1.Nodes.Add "*" & three1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 9) & " " & rec2.Fields(4)
                four1 = rec2.Fields(3)
            ElseIf UCase(rec2.Fields(2)) = "FIVE" Then
                TreeView1.Nodes.Add "*" & four1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 11) & " " & rec2.Fields(4)
                five1 = rec2.Fields(3)
            End If
            dept1 = rec2.Fields(0)
        Else
            If UCase(rec2.Fields(2)) = "ONE" Then
                TreeView1.Nodes.Add "*" & rec2.Fields(0) & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 3) & " " & rec2.Fields(4)
                one1 = rec2.Fields(3)
            ElseIf UCase(rec2.Fields(2)) = "TWO" Then
                TreeView1.Nodes.Add "*" & one1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 5) & " " & rec2.Fields(4)
                two1 = rec2.Fields(3)
            ElseIf UCase(rec2.Fields(2)) = "THREE" Then
                TreeView1.Nodes.Add "*" & two1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 7) & " " & rec2.Fields(4)
                three1 = rec2.Fields(3)
            ElseIf UCase(rec2.Fields(2)) = "FOUR" Then
                TreeView1.Nodes.Add "*" & three1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 9) & " " & rec2.Fields(4)
                four1 = rec2.Fields(3)
            ElseIf UCase(rec2.Fields(2)) = "FIVE" Then
                TreeView1.Nodes.Add "*" & four1 & "*", tvwChild, "*" & CStr(rec2.Fields(3)) & "*", Left(rec2.Fields(1), 11) & " " & rec2.Fields(4)
                five1 = rec2.Fields(3)
            End If
            dept1 = rec2.Fields(0)
        End If
        rec2.MoveNext
    Loop
End If
End Sub





我尝试过:



treeview没有填充别人帮助我



What I have tried:

treeview is not populating plese someone help me

推荐答案

甚至不尝试:重写它从头开始使用VB6代码的功能作为规范。 C#使用.NET框架,它的控件(以及它们依赖的属性和方法)与VB6等价物不同。



如果你写的话VB6代码,然后您需要了解C#以使其在.NET应用程序的更广泛的上下文中工作 - 如果您没有,那么找一些与.NET相关的代码执行相同的工作!
Don't even try: rewrite it from scratch using the functionality of the VB6 code as a specification instead. C# uses the .NET framework, and it's controls (as well as the properties and methods they rely on) are not the same as the VB6 equivalent.

If you wrote the VB6 code, then you need to understand C# to make it work in the wider context of a .NET application anyway - and if you didn't, then find some .NET related code that does the same job instead!


正如我的同事所说:你必须从头开始重写代码。如果您知道上面的代码正在做什么,这很容易。



有一些对象在使用,例如记录集(带下划线):

As my colleagues stated: you have to rewrite the code from scratch. This is quite easy, if you know what above code is doing.

There are some objects in use, such as recordsets (underlined):
If rec2.EOF = False And rec2.BOF = False Then
    Do While rec2.EOF = False





即使你可以创建记录集对象(如何:打开ADO连接和RecordSet对象Visual C#.NET [ ^ ])你不应该这样做,因为使用它是相当古老的技术。



我建议使用 ADO.NET [ ^ ]连接数据库。然后,您将能够使用 Command 将数据提取到 Reader 。您可以遍历存储在阅读器中的数据以填充TreeView。因为您没有提供您使用的数据库,所以我无法提供更多详细信息。



欲了解更多详情,请参阅:

ADO.NET代码示例 [ ^ ]



Even if you can create recordset object (HOW TO: Open ADO Connection and RecordSet Objects in Visual C# .NET[^]) you shouldn't do that, because it's pretty old technology.

I'd recommend to use ADO.NET[^] to connect to the database. Then you'll be able to use Command to fetch data into Reader. You can loop through the data stored in a reader to populate TreeView. Because you didn't provide what database you use, i can't provide more details.

For further details, please see:
ADO.NET Code Examples[^]


这篇关于任何人都可以将我的VB代码写入C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆