VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 检验数据库中的字段
发表评论(0)作者:Ian Moore, 平台:VB6.0+Win98, 阅读:11737, 日期:2001-04-30
Check Fields in a Database

Tip by Ian Moore

Tip description

This dll Function will run through a database that you have created and check for field that you wish to look for.

Tip Code


Option Explicit
Dim cnADODB As ADODB.Connection
Dim strSQL As String
Dim rsGeneric As New ADODB.Recordset
Private Sub Class_Initialize()

   Set cnADODB = New ADODB.Connection
  cnADODB.ConnectionString = "PROVIDER=MSDASQL;dsn=Northwind;uid=;pwd=;database=Northwind;"

End Sub
Public Function CheckField(ByVal sF As String, ByVal sF2 As String, ByVal sT As String) As Boolean
On Error GoTo CheckErr
    CheckField = False
    
    cnADODB.Open
    
    strSQL = "SELECT " & sF & " FROM " & sT
    
    Set rsGeneric = cnADODB.Execute(strSQL)
    If rsGeneric.EOF And rsGeneric.BOF Then
        Set rsGeneric = Nothing
        CheckField = False
        Exit Function
    End If
        
        Do While Not rsGeneric.EOF
            If sF2 = rsGeneric(sF).Value Then
                CheckField = True
                Exit Function
            End If
          rsGeneric.MoveNext
        Loop

    rsGeneric.Close
    cnADODB.Close
CheckErr:
      Debug.Print Err.Number & Err.Description
   Err.Clear
   CheckField = False
   Exit Function
End Function