2013-07-09 56 views
-1

我是編程新手,我的問題是。我已經把我的ado數據庫連接字符串放入一個文本框中,我該如何調用該文本框?我在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 

回答

1

您可以通過連接字符串作爲參數傳遞給Connection.Open method 如(假設文本框的名稱是Text1155):

Dim conas As New ADODB.Connection 

conas.Open Text1155.Text 

(你不需要括號用於調用子在vb6) 你的代碼看起來很對其他人...

+0

...任何運氣呢? – mortb