haveField=false for each i in rs.fields if i.name="字段" then haveField=true exit for end if nextif haveField then msgbox "字段存在!"
循环一下Fields判断Rs.Fields.Item(index).Name
顶楼上的. 另外 如果sql数据库可以查数据库表 select * from syscolumns a,sysobjects b where a.id=b.id and a.name='字段' and b.name='表'
dim fld as Field for each fld in rs.fields if fld.name="字段" then msgbox "字段存在!" exit for end if next
Dim cn As ADODB.Connection, rs As ADODB.Recordset Dim i As Integer Dim TheFieldExisting As Boolean Dim strField As StringSet cn = New ADODB.Connection cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB;Persist Security Info=False" cn.OpenSet rs = New ADODB.Recordset rs.Open ("SELECT * FROM titles"), cn'方法一 For i = 0 To rs.Fields.Count - 1 If UCase(rs.Fields(i).Name) = "TITLE" Then TheFieldExisting = True Exit For End If Next i MsgBox "Field [Title] " & IIf(TheFieldExisting, "", "Not ") & "in Place"'方法二 On Error Resume Next strField = rs!UserName If Err.Number = 3265 Then TheFieldExisting = False MsgBox "Field [UserName] " & IIf(TheFieldExisting, "", "Not ") & "in Place"
for each i in rs.fields
if i.name="字段" then
haveField=true
exit for
end if
nextif haveField then msgbox "字段存在!"
另外
如果sql数据库可以查数据库表
select * from syscolumns a,sysobjects b where a.id=b.id and a.name='字段' and b.name='表'
for each fld in rs.fields
if fld.name="字段" then
msgbox "字段存在!"
exit for
end if
next
Dim i As Integer
Dim TheFieldExisting As Boolean
Dim strField As StringSet cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB;Persist Security Info=False"
cn.OpenSet rs = New ADODB.Recordset
rs.Open ("SELECT * FROM titles"), cn'方法一
For i = 0 To rs.Fields.Count - 1
If UCase(rs.Fields(i).Name) = "TITLE" Then
TheFieldExisting = True
Exit For
End If
Next i
MsgBox "Field [Title] " & IIf(TheFieldExisting, "", "Not ") & "in Place"'方法二
On Error Resume Next
strField = rs!UserName
If Err.Number = 3265 Then TheFieldExisting = False
MsgBox "Field [UserName] " & IIf(TheFieldExisting, "", "Not ") & "in Place"