当前位置: 动力学知识库 > 问答 > 编程问答 >

database - VB6 MS-Access returns wrong 'AllowZeroLength' value

问题描述:

I'm using VB6 with ADOX to check the properties of Access 97 table columns.

For the text fields it's important to prove that the field allows zero length or not.

The problem: the returned value is inverted.

If the field allows zero length the return is false, if the field doesn't the value is true.

If a field doesn't support this property it returns false, which is right.

Could someone explain why the return is inverted?

Private Sub ReadTableStructure()

Dim Cat As ADOX.Catalog

Dim Tbl As ADOX.Table

Dim Col As ADOX.Column

Set Cat = New ADOX.Catalog

Set Cat.ActiveConnection = Conn

For Each Tbl In Cat.Tables

For Each Col In Tbl.Columns

bAllowZeroLength = GetDBPropertyBool(Col.Properties, "Jet OLEDB:Allow Zero Length", True)

Next Col

Next Tbl

End Sub

The Function GetDBPropertyBool:

Private Function GetDBPropertyBool(Properties As ADOX.Properties, sName As String, bDefaultValue As Boolean) As Boolean

Dim Prop As ADOX.Property

Set Prop = Properties(sName)

If Prop Is Nothing Then

GetDBPropertyBool = bDefaultValue

Else

GetDBPropertyBool = Prop.Value

End If

End Function

In Access this property is true, in the VB6 Object it's false.

EDIT:

I just found out that when i'm opening the table in Access in edit mode and just saving, the values which are given in VB6 are right. I don't change anything, just open to edit and save. Does anyone had already this problem?

网友答案:

Actually I don't found an answer, why I am getting these wrong values. To open and save every table is no solution for us and our customers.

I just found an workaround, by using DAO to read the property rightly.

Private Sub ReadTableStructure(DB As DAO.Database)
    Dim i As Integer, j As Integer
    Dim Fld As DAO.Field
    Dim tdfLoop As TableDef

    For i = 0 To DB.TableDefs.Count - 1
        Set tdfLoop = DB(i)   
        For j = 0 To tdfLoop.Fields.Count - 1
            bAllowZeroLength = tdfLoop.Fields(j).AllowZeroLength
        Next j
    Next i
End Sub

If someone got an answer, why ADO doesn't returns the right value, please let me know.

分享给朋友:
您可能感兴趣的文章:
随机阅读: