先引用 Microsoft ActiveX Data Objects 2.x Library
Dim ADO_Rset As New ADODB.Recordset
dim AdoStr As String
'如果你的数据库不是 2000或以上的.那么Microsoft.Jet.OLEDB应该是3.0
AdoStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\vbproject\data\test.mdb;Persist Security Info=False"
    With ADO_Rset
       .ActiveConnection = AdoStr
       .CursorLocation = adUseClient
       .CursorType = adOpenStatic
       .LockType = adLockBatchOptimistic
       .Source = "ALTER TABLE 表1 ADD  字段1 text(30)"
       .Open
    End With
    Set ADO_Rset = Nothing
这是增加字段,如何判断是否存在可根据上述代码返回的错误情况判断

解决方案 »

  1.   

    dim bl as boolean
    bl=false
    for i=0 to ado_rset.RecordCount
       if 字段=ado_rset.fields(i).name then
           bl=true
       end if
    next i然后根据返回的bl值不就可以判断是不是存在了吗?
      

  2.   

    sorry,数据记录的列数不是recordcount,所以上边的程序应该改为
    on error goto 1
    do while ado_rset.fields(i).name<>null
        if 字段=ado_rset.fields(i).name then
           bl=true
        end if
    loop1:
    exit sub
      

  3.   

    最后答案 :
    dim bl as boolean
    bl=false
    for i=0 to ado_rset.Fields.Count-1
       if 字段=ado_rset.fields(i).name then
           bl=true
       end if
    next i