我在创建在 Oracle 数据库中执行存储过程的控制台 vb.net 程序时遇到问题。如果存储过程将在代码中进行硬编码,我可以这样做。问题是,存储过程需要放在供应商程序的参数中。目前,我们使用 VB6 程序来执行此操作。现在,他们想将此 vb6 程序转换为 .NET,但我不知道该怎么做。我尝试了下面的方法,但它没有从 3rd 方程序传递命令参数。
例子。这是第3方程序的截图:
PLSQLSUB.exe 程序是一个调用存储过程 CNC_UNLOCK_USERS 的 vb6。
这是 VB6 代码,目前正在运行,但我不知道如何在 VB.NET 中传递外部参数
Private Sub Form_Load()
Dim cnTrecs As New ADODB.Connection
Dim QY As New ADODB.Command
Dim I As Integer
Dim Procedures(10) As String
Dim ColonPos As Integer
Dim CommLine As String
Dim CommLength As Integer
Dim StartPos As Integer
Dim FileName As String
Dim CheckForFile As String
Dim User As String
Dim Pass As String
Dim Userid As String
Dim Password As String
Dim PLSCount As Integer
PLSCount = 0
CommLine = Command()
CommLength = Len(Trim(CommLine))
If Trim(CommLine) <> "" Then
StartPos = 1
For I = 1 To 10
ColonPos = InStr(StartPos, Trim(CommLine), ";")
If ColonPos > 0 Then
Procedures(I) = Mid(CommLine, StartPos, ColonPos - StartPos)
PLSCount = PLSCount + 1
StartPos = ColonPos + 1
ElseIf I > 1 Then
If (CommLength - StartPos) > 0 Then
Procedures(I) = Mid(CommLine, StartPos, CommLength - StartPos)
MsgBox (Procedures(I))
PLSCount = PLSCount + 1
Exit For
Else
Exit For
End If
Else
Procedures(I) = Trim(CommLine)
PLSCount = PLSCount + 1
Exit For
End If
Next
Exit Sub
Else
Unload Me
Exit Sub
End If
CheckForFile = Dir("C:\VB\vbtext1.txt")
If CheckForFile <> "" Then FileName = "d:\VB\vbtext1.txt"
Open FileName For Input As #5 ' Open UserID and Password file.
Line Input #5, Userid
Line Input #5, Password
Close #5
End If
User = Mid(Userid, 1) ' Set database userID
Pass = Mid(Password, 1) ' Set database password
cnTrecs.Open "DSN=PLSQLSUB;" _
& "Uid=" _
& Trim$(User) & ";PWD=" _
& Trim$(Pass)
For I = 1 To PLSCount ' Loop until end of plsql procedures
Print #1, "The Stored Procedure " & Procedures(I) & " was submitted for execution
on/at "; Format(Now, "dd-mmm-yyyy hh:mm:ss")
Set QY.ActiveConnection = cnTrecs
QY.CommandType = adCmdStoredProc
QY.CommandText = Procedures(I)
QY.Execute
Print #1, "The Stored Procedure " & Procedures(I) & " completed execution on/at ";
Format(Now, "dd-mmm-yyyy hh:mm:ss")
Print #1, " "
Next I
If cnTrecs.State = adStateOpen Then
cnTrecs.Close
End If
End Sub
一位朋友告诉我使用以下代码,但我无法通过存储过程。任何帮助将不胜感激。
Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
For i As Integer = 0 To CommandLineArgs.Count - 1
MessageBox.Show("The stored procedure is: " + CommandLineArgs(i))
Next