使用 SQL 将 VB6 转换为 VB.NET

Converting VB6 to VB.NET with SQL

我想弄清楚这段代码是如何工作的,因为它来自 VB6,我正在将它转换为 VB.NET,该程序的前任开发人员告诉我 lstrvalue 是一个 SQL 代码,但我没有看到像 SELECT、UPDATE 等任何常见语句,这就是我不理解它的原因。

rs.Open "Select AccountCode,rtrim(type) as type, rtrim(left(formula,3)) as bet1,ltrim(right(formula,3))as bet2 from vwTempTableWP where rtrim(type) in('SUM','+','-') order by orderby", con
If rs.EOF Then
Else
    rs.MoveFirst

    Do While rs.EOF <> True

        codetype = Trim(rs!AccountCode)
        tipo = Trim(rs!Type)
        bet1 = CDbl(Trim(rs!bet1))
        bet2 = CDbl(Trim(rs!bet2))

        If tipo = "SUM" Then
            lstrValue = "execute sp_sum '" & Trim(codetype) & "','Working'," & CDbl(bet1) & "," & CDbl(bet2) & ""
            con.Execute lstrValue
            'Do While con.State = adStateExecuting
            'Loop
        ElseIf tipo = "+" Then
            lstrValue = "execute sp_add '" & Trim(codetype) & "','" & Trim(report) & "'," & CDbl(bet1) & "," & CDbl(bet2) & ""
            con.Execute lstrValue
            'Do While con.State = adStateExecuting
            'Loop
        ElseIf tipo = "-" Then
            lstrValue = "execute sp_minus '" & Trim(codetype) & "','" & Trim(report) & "'," & CDbl(bet1) & "," & CDbl(bet2) & ""
            con.Execute lstrValue
            'Do While con.State = adStateExecuting
            'Loop
        End If
        rs.MoveNext
    Loop
    rs.Close
End If

您发布的代码正在构建 SQL 语句来执行 stored procedure,特别是 sp_sumsp_addsp_minus 之一。您的 SQL 服务器文档应该解释什么是存储过程,并且在 SQL Server Management Studio 中检查它们的源代码应该向您展示它们各自的作用.