推荐于2016-04-01
展开全部
下面代码显示把table name 和field name填到一个Combo box里。
Function GetTables(cnn As ADODB.Connection) As Boolean
'Purpose : Get table names from the Connection given
'Input : cnn, ther ADODB.Connection
'Output : TRUE/FALSE
'
On Error GoTo GetTables_ErrorHandler
Screen.MousePointer = 11
Dim rstSchema As ADODB.Recordset
cboTablesName.Clear
Set rstSchema = cnn.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "Table"))
Do Until rstSchema.EOF
If StrComp(Left(rstSchema!TABLE_NAME, 4), "MSys", vbTextCompare) <> 0 Then
cboTablesName.AddItem rstSchema!TABLE_NAME
End If
rstSchema.MoveNext
Loop
rstSchema.Close
Set rstSchema = Nothing
Screen.MousePointer = 0
ErrorHandler:
Exit Function
GetTables_ErrorHandler:
Screen.MousePointer = 0
ShowErrMsg ("GetTables")
Resume ErrorHandler
End Function
Function GetFields(strTableName As String, cnn As ADODB.Connection) As Boolean
'Purpose : Get field names from the table selected and Connection given
'Input : strTableName - the table name; cnn - ther ADODB.Connection
'Output : TRUE/FALSE
'
On Error GoTo GetFields_ErrorHandler
Screen.MousePointer = 11
Dim adoFields As ADODB.Fields
Dim rstTable As ADODB.Recordset
Dim strSQL As String
cboFieldsName.Clear
strSQL = "SELECT TOP 1 * FROM [" & strTableName & "] "
Set rstTable = New ADODB.Recordset
rstTable.Open strSQL, cnn, adOpenStatic, adLockPessimistic, adCmdText
Dim fld As ADODB.Field
For Each fld In rstTable.Fields
cboFieldsName.AddItem fld.Name
Next
rstTable.Close
Set rstTable = Nothing
Screen.MousePointer = 0
ErrorHandler:
Exit Function
GetFields_ErrorHandler:
Screen.MousePointer = 0
ShowErrMsg ("GetFields")
Resume ErrorHandler
End Function
追问
就只有这里吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询