M
Miro
Something weird I have run into when trying to add a boolean field to an
Access table by code.
-Just wondering if anyone else has run into this. ( vb.net 2005 express )
If I add any other field other than boolean the "command" version of adding
a field works great.
But if I try to add a boolean field, I get an exception error when its
trying to be added, so instead I have to use the function meathod.
-Code is below.
so basically I have to use Columns.Append( blablalblba
instead of the other way.
-All works...but just seemed to be a funny solution and I did tried it by
fluke and waisted a lot of my time trying to figure out why I couldnt add a
logical field.
So at least it will same some other person still trying to use adox.
Cheers
Miro
? TableFields(17)
{Simply_Teaching.FileLayout}
Prop_DBName: "MyDBName"
Prop_FieldLength: 1
Prop_FieldName: "BoolTest"
Prop_FieldType: "Logical"
Prop_TableName: "TableName"
Prop_VersionNo: "1.00"
Prop_KeyIndexField: False
======================
Dim NewAddingColumn As New ADOX.Column()
If TableFields(intFileSetup).Prop_FieldType =
"Logical" Then
ADOXTable(TableintFileSetup).Columns.Append( _
TableFields(intFileSetup).Prop_FieldName, _
ReturnFieldType(TableFields(intFileSetup).Prop_FieldType),
_
TableFields(intFileSetup).Prop_FieldLength)
Else
NewAddingColumn.Name =
TableFields(intFileSetup).Prop_FieldName
NewAddingColumn.Type =
ReturnFieldType(TableFields(intFileSetup).Prop_FieldType)
If TableFields(intFileSetup).Prop_FieldType <>
"Date" And _
TableFields(intFileSetup).Prop_FieldType <>
"Memo" Then
NewAddingColumn.DefinedSize =
TableFields(intFileSetup).Prop_FieldLength
End If
If TableFields(intFileSetup).Prop_KeyIndexField
= False Then
NewAddingColumn.Attributes =
ADOX.ColumnAttributesEnum.adColNullable
Else
NewAddingColumn.Attributes =
ADOX.ColumnAttributesEnum.adColFixed
End If
'Append the Column to the table.
ADOXTable(TableintFileSetup).Columns.Append(NewAddingColumn)
End If
=======================
Private Function ReturnFieldType(ByVal FieldType As String) As
ADOX.DataTypeEnum
Dim DataType As ADOX.DataTypeEnum
If FieldType = "String" Then
DataType = ADOX.DataTypeEnum.adVarWChar
ElseIf FieldType = "Date" Then
'DataType = ADOX.DataTypeEnum.adDBDate 'Throws out an error
DataType = ADOX.DataTypeEnum.adDate
ElseIf FieldType = "Logical" Or FieldType = "Boolean" Then
'datatype = adox.DataTypeEnum.
DataType = ADOX.DataTypeEnum.adBoolean
ElseIf FieldType = "Memo" Then
DataType = ADOX.DataTypeEnum.adLongVarWChar
End If
Return DataType
End Function
Access table by code.
-Just wondering if anyone else has run into this. ( vb.net 2005 express )
If I add any other field other than boolean the "command" version of adding
a field works great.
But if I try to add a boolean field, I get an exception error when its
trying to be added, so instead I have to use the function meathod.
-Code is below.
so basically I have to use Columns.Append( blablalblba
instead of the other way.
-All works...but just seemed to be a funny solution and I did tried it by
fluke and waisted a lot of my time trying to figure out why I couldnt add a
logical field.
So at least it will same some other person still trying to use adox.
Cheers
Miro
? TableFields(17)
{Simply_Teaching.FileLayout}
Prop_DBName: "MyDBName"
Prop_FieldLength: 1
Prop_FieldName: "BoolTest"
Prop_FieldType: "Logical"
Prop_TableName: "TableName"
Prop_VersionNo: "1.00"
Prop_KeyIndexField: False
======================
Dim NewAddingColumn As New ADOX.Column()
If TableFields(intFileSetup).Prop_FieldType =
"Logical" Then
ADOXTable(TableintFileSetup).Columns.Append( _
TableFields(intFileSetup).Prop_FieldName, _
ReturnFieldType(TableFields(intFileSetup).Prop_FieldType),
_
TableFields(intFileSetup).Prop_FieldLength)
Else
NewAddingColumn.Name =
TableFields(intFileSetup).Prop_FieldName
NewAddingColumn.Type =
ReturnFieldType(TableFields(intFileSetup).Prop_FieldType)
If TableFields(intFileSetup).Prop_FieldType <>
"Date" And _
TableFields(intFileSetup).Prop_FieldType <>
"Memo" Then
NewAddingColumn.DefinedSize =
TableFields(intFileSetup).Prop_FieldLength
End If
If TableFields(intFileSetup).Prop_KeyIndexField
= False Then
NewAddingColumn.Attributes =
ADOX.ColumnAttributesEnum.adColNullable
Else
NewAddingColumn.Attributes =
ADOX.ColumnAttributesEnum.adColFixed
End If
'Append the Column to the table.
ADOXTable(TableintFileSetup).Columns.Append(NewAddingColumn)
End If
=======================
Private Function ReturnFieldType(ByVal FieldType As String) As
ADOX.DataTypeEnum
Dim DataType As ADOX.DataTypeEnum
If FieldType = "String" Then
DataType = ADOX.DataTypeEnum.adVarWChar
ElseIf FieldType = "Date" Then
'DataType = ADOX.DataTypeEnum.adDBDate 'Throws out an error
DataType = ADOX.DataTypeEnum.adDate
ElseIf FieldType = "Logical" Or FieldType = "Boolean" Then
'datatype = adox.DataTypeEnum.
DataType = ADOX.DataTypeEnum.adBoolean
ElseIf FieldType = "Memo" Then
DataType = ADOX.DataTypeEnum.adLongVarWChar
End If
Return DataType
End Function