-1

我是编程新手,我的问题是。我已将我的 ado db 连接字符串放入文本框中,我该如何调用该文本框?我在 vb 6 中创建我的程序,这是我的代码。

Private Sub lvButtons_H2_Click()
On Error GoTo errtrap
If Label47.Caption = "True" Then
MsgBox "INITIAL SETTING FOR SHIP ACCOUNT IS BEING PERFORMED", vbOKOnly, "ABORT"
Exit Sub
End If
Dim conas As New ADODB.Connection, rs01 As New ADODB.Recordset, rsx1 As New ADODB.Recordset, RS9 As New ADODB.Recordset
conas.Connectio`enter code here`nString = Text1155.Text
conas.Open
Set RS9 = New ADODB.Recordset
    RS9.ActiveConnection = conas
    RS9.CursorType = 3
    RS9.LockType = 3
    RS9.Open ("SELECT  * FROM [SHIPACCOUNT].[dbo].[SPARE PART LIST BOND 29 MONTHLY] WHERE NAMECODE = " & Text2.Text & "")
    Set DataReport2.DataSource = RS9

    DataReport2.Sections("Section2").Controls.item("LABEL12").Caption = Text1.Text
    DataReport2.Sections("Section2").Controls.item("LABEL11").Caption = Text3.Text

    DataReport2.Sections("Section1").Controls.item("TEXT1").DataField = RS9![PARTSNAME].Name
    DataReport2.Sections("Section1").Controls.item("TEXT2").DataField = RS9![Price].Name
    DataReport2.Sections("Section1").Controls.item("TEXT3").DataField = RS9![unit].Name
    DataReport2.Sections("Section1").Controls.item("TEXT4").DataField = RS9![QTYAPPLY].Name
    DataReport2.Sections("Section1").Controls.item("TEXT5").DataField = RS9!QTYAPPROVE.Name
    DataReport2.Sections("Section1").Controls.item("TEXT6").DataField = RS9![AMOUNTAPPROVE].Name
    DataReport2.Sections("Section1").Controls.item("TEXT7").DataField = RS9![Date].Name


DataReport2.Show 1

Exit Sub
errtrap:
MsgBox Err.Description, vbCritical, "The system encountered an error"
End Sub
4

1 回答 1

1

您可以将连接字符串作为参数传递给Connection.Open method 例如(假设文本框的名称是Text1155):

Dim conas As New ADODB.Connection

conas.Open Text1155.Text

(在 vb6 中调用 Sub 不需要括号)否则您的代码看起来正确...

于 2013-07-09T06:50:02.767 回答