|
本帖最后由 鱼儿游游 于 2011-12-8 19:22 编辑
用ADO读取记录集,如何判断一个ACCESS字段是否为自动编号?
判断SQL数据库的我已解决,写了一个通用函数,调用即可。
'
'判断某列是否是标识列:是标识列,则返回:True、否则返回:False
Public Function IsIdentityField(ByVal strFieldName As String, ByVal strTableName As String) As Boolean
On Error GoTo Err_Handler
Dim blnResult As Boolean
Dim varValue As Variant
Dim rst As Object
Dim strSQL As String
blnResult = False
varValue = 0
strSQL = "SELECT COLUMNPROPERTY(OBJECT_ID('" & strTableName & "'),'" & strFieldName & "','IsIdentity')"
If GetRecordset(rst, strSQL) Then
If rst.RecordCount > 0 Then
varValue = Nz(rst.Fields(0).Value, "NotFould")
End If
rst.Close
End If
If varValue = "NotFould" Then
MsgBox "指定的数据表名[" & strTableName & "] 或 字段名[" & strFieldName & "]不存在!", vbExclamation, "提示"
Else
blnResult = varValue <> 0
End If
Exit_Handler:
IsIdentityField = blnResult
Set rst = Nothing
Exit Function
Err_Handler:
blnResult = False
MsgBox Err.Description, vbExclamation, "判断列是否是标识列出错"
Resume Exit_Handler
End Function
|
|