Option Explicit Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim m_FldsName() As String Private Sub Command1_Click() Dim II As Long Dim t As Single cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=广商;Data Source=SUPER" rs.Open "Select * from FldSet ", cn, adOpenKeyset Do Until rs.EOF = True rs.MoveNext Loop rs.MoveFirst t = Timer ReDim m_FldsName(rs.Fields.Count) For II = 0 To rs.Fields.Count - 1 m_FldsName(II) = rs.Fields(II).Name Next Do Until rs.EOF = True ReadFieldsNotOnErr "Err1" ReadFieldsNotOnErr "TableName" ReadFieldsNotOnErr "Err2" rs.MoveNext Loop MsgBox "NotErr:" & Timer - t On Error Resume Next rs.MoveFirst t = Timer Do Until rs.EOF = True ReadFieldsOnErr "Err1" ReadFieldsOnErr "TableName" ReadFieldsOnErr "Err2" rs.MoveNext Loop MsgBox "OnErr:" & Timer - t rs.Close cn.Close End Sub Private Sub ReadFieldsOnErr(FieldName As String) Dim v As Variant v = rs(FieldName).Value End Sub Private Sub ReadFieldsNotOnErr(FieldName As String) Dim II As Long Dim IsExists As Boolean Dim v As Variant IsExists = False For II = 0 To UBound(m_FldsName) - 1 If m_FldsName(II) = FieldName Then IsExists = True Exit For End If Next If IsExists = True Then v = rs(FieldName).Value End If End Sub =================================== |