用ado读取一个dbf表获得一个Recordset,但是由于系统升级的原因导致从各个地区发来的dbf表结构有的不是最新的,一般是缺少字段,怎么判断一个Recordset里是否存在某个字段呢?

解决方案 »

  1.   

    随便一写,这个逻辑应该可以
    for i=0 to rs.fields.count-1
       if rs.fields.name=你要找到的字段名 then
          exit for
       end if
    next
    if i<=rs.fields.count-1 then
       存在
    else
       不存在
    endif
      

  2.   

    楼上的办法,for循环就可以了
      

  3.   


        For i = 0 To rs.RecordCount - 1
            Print rs.Fields(i).Name
        Next
      

  4.   

    呵呵,我上面错了
        For i = 0 To rs.Fields.Count - 1
            Print rs.Fields(i).Name
        Next
      

  5.   

    写个函数判断.
    Private Function ExistFields(rs As ADODB.Recordset, FieldName As String) As Boolean
    Dim i As Integer
    For i = 0 To rs.Fields.Count - 1
        If LCase(rs.Fields(i).Name) = LCase(FieldName) Then
            ExistFields = True
            Exit For
        End If
    Next i
    End Function
      

  6.   

    我也写错了,下面这样才对,呵呵for i=0 to rs.fields.count-1
       if rs.fields(i).name=你要找到的字段名 then
          exit for
       end if
    next
    if i<=rs.fields.count-1 then
       存在
    else
       不存在
    endif