【发布时间】:2019-02-14 15:01:34
【问题描述】:
我在 VB6 中有一部分代码,我正在尝试将其转换为 VB.net。特别是记录集。
这是VB6代码的一部分:
Data19.RecordSource = "select id from headers where type=12"
Data19.Refresh
If Data19.Recordset.RecordCount > 0 Then
Data6.RecordSource = "select sum(left * right) from footers where type=12"
Data6.Refresh
ss = Format(Data6.Recordset.Fields(0), "0.00")
Data19.Recordset.MoveLast
a = Data19.Recordset.RecordCount - 1
Data19.Recordset.MoveFirst
For i = 0 To a
If i > 0 Then Data19.Recordset.MoveNext
Data22.RecordSource = "select * from documents where type=12"
Data19.Recordset.Fields(0)
Data22.Refresh
With Data22.Recordset
If .RecordCount > 0 Then
.MoveLast
b = .RecordCount - 1
.MoveFirst
For j = 0 To b
If j > 0 Then .MoveNext
If .Fields("link1") < ra And .Fields("code") <> "00" Then
.Edit
.Fields("link1") = ra
.Fields("pc") = Format(.Fields("dpc") * (100 - ra) / 100, "0.00")
.Fields("total") = Format(.Fields("amount") * .Fields("dpc") * (100 - ra) / 100, "0.00")
.Update
End If
Next
End If
End With
Next
End If
我对@987654322@、.MoveFirst、.Recordset有点困惑。
在我的 VB.net 代码中,我一直在使用这个函数从数据库中获取我想要的表:
Public Function returnTable(ByVal queryString As String)
Dim query1 As String = queryString
'Console.WriteLine(query1)
Dim table As New DataTable
Using connection As New MySqlConnection(connection)
Using adapter As New MySqlDataAdapter(query1, connection)
Dim cmb As New MySqlCommandBuilder(adapter)
table.Clear()
adapter.Fill(table)
Return table
End Using
End Using
End Function
所以如果我没记错的话,带有记录源的部分应该是这样的:
Dim data19 as new datatable
Data19 = returnTable("select id from headers where type=12")
但后来,在代码中,我无法弄清楚如何编写 .MoveLast、.MoveFirst、.Recordset、.MoveNext 等的等价物...
【问题讨论】:
-
看大局——vb6的大块是做什么的?只需在 vb.net 中开发,不要卡在逐行转换代码上。如果您不知道它的作用并尝试逐行转换,那么您可能无论如何都不会成功!
-
如果您有很多代码,请考虑参考 ADO - 您的代码将像以前一样工作。
标签: vb.net vb6-migration