在旧版本的vb中使用的adocom问题

时间:2019-01-24 13:28:20

标签: vb.net

我正在一个项目上,必须引用一个已经完成的项目。在经历[此处输入图像描述] [1]时,我遇到了一个问题,无法理解代码 我想知道adosetup在做什么。 Msmt_system是表名 虽然msmt_sys_desc和msmt_sys_val是msmt_system中的列 dbcBoLC是datacombobox

datacombo如何知道从哪个表访问数据?

Call adoSetup(AdoCom, "Msmt_System", True, dbcBoLC, "Msmt_Sys_Desc", 
     "Msmt_Sys_val")
Call dbcBoLC_Click(1)

'in another file:
Public Sub adoSetup(adoCtrl As Adodc, sRecSrc As String, 
           bLinkAdoCtrl As Boolean, 
           Optional dCombo As DataCombo, 
           Optional sListField As String, 
           Optional sBoundCol As String)

   'Added On: 25/07/2003
   sAppPath = App.Path & "\MultiGauging.mdb"    'Store the Application Path
   sDbConn_String = "DBQ=" & sAppPath & ";Driver={Microsoft Access Driver (*.mdb)};pwd=*****;UID=admin;UserCommitSync=Yes;"

   'Begin: Setup the connection string and apply to datacontrol
   With adoCtrl
     .ConnectionString = sDbConn_String
     .RecordSource = sRecSrc
     .Refresh
   End With
   'End: Setup the connection string and apply to datacontrol

   'Begin: Setup the corresponding combo box
   If bLinkAdoCtrl Then
     Set dCombo.RowSource = adoCtrl
     dCombo.ListField = sListField
     dCombo.BoundColumn = sBoundCol

     If Not (adoCtrl.Recordset.EOF Or adoCtrl.Recordset.BOF) Then
        adoCtrl.Recordset.MoveFirst
        dCombo.BoundText = adoCtrl.Recordset(sBoundCol)
     End If
   End If
   'End: Setup the corresponding combo box
End Sub

1 个答案:

答案 0 :(得分:0)

在您的通话中:

Call adoSetup(AdoCom, "Msmt_System", True, dbcBoLC, . . .

表名是第二个参数。这样便可以知道要使用哪个表(记录源)。您的子adoSetup只是建立一个连接(ConnectionString = sDbConn_String)查询一个表(RecordSource = sRecSrc),然后将数据附加到一个组合框(该子框的参数arg 4:dbcBoLC) 。数据组合仅使用adoCtrl中设置的任何表格。