2013-07-09 40 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