|
-
Feb 19th, 2002, 07:56 PM
#1
Thread Starter
Junior Member
Adox
I'm trying to alter a column (set a field to nullable) using ADOX with Jet 4.0 OLE DB provider, however I've been getting some errros trying to do it.
After surfing MSDN, I found this --- BUG: Attributes Property of ADOX Columns Collection May Cause Append Method to Fail. In this particular document, the workaround is -- If you need to create a nullable or fixed length column, you must create the table through some mechanism other than ADOX, such as DDL SQL statements (CREATE TABLE, for example).
After a few more surfing, I found yet another document (A More Powerful SQL
The Jet 4.0 ANSI SQL-92 Extensions
by Paul Litwin, Ken Getz, and Mike Gilbert). It discussed Jet 4.0's enhanced ANSI-SQL support including ALTER COLUMN, but didn't have anything about setting (altering) a column Nullable property.
Would anyone out there know what I can do to achieve this???
Thanks heaps!!!
-
Feb 20th, 2002, 03:08 AM
#2
Hyperactive Member
This may be old-fashioned but if you need that much control you need to use good old DAO, as admitted by Micro$oft themselves: http://msdn.microsoft.com/library/de...cesstables.asp
Quote from the bottom of this ADOX page:
You must establish a reference to the Microsoft DAO 3.6 object library and use DAO code to programmatically set these remaining table properties: Description, Filter, OrderBy, LinkChildFields, LinkMasterFields, SubdatasheetExpanded, SubdatasheetName, and SubdatasheetHeight. For information about working with these properties, search Microsoft Access Help.
Graham, www.gab2001uk.com VBExplorer Forum Moderator VBExplorer
www.gab2001uk.com For comparing and contrasting DAO with ADO
Code for Creating, Copying, Compacting, Replicating, Synchronising Access 97/2000 databases plus showing Schemas and using .Seek
-
Feb 20th, 2002, 05:17 AM
#3
Frenzied Member
Code:
Public Sub subCreateNewDatabase(DbFile As String)
On Local Error Resume Next
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim idx As New ADOX.Index
'Engine Type=5 = access 200, Engine Type=4 = access 97
cat.Create "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbFile & _
";Jet OLEDB:Engine Type=5"
'adBoolean Boolean
'adInteger Long
'adSmallInt Integer
'adLongVarWChar Memo
'adDate Date
'adDouble Double
'adCurrency Currency
'adLongVarBinary OLE Object
'adWChar Text
tbl.Name = "MyTable"
Set tbl.ParentCatalog = cat
subAddField tbl, "Timefield", adDate
subAddField tbl, "Numericfield", adDouble
subAddField tbl, "MemoField", adLongVarWChar
cat.Tables.Append tbl
Set cat = Nothing
End Sub
Private Sub subAddField(tbl As ADOX.Table, Name As String, DataType As Integer, Optional FieldLenght As Integer, Optional Auto As Boolean)
On Local Error Resume Next
Select Case DataType
Case adInteger, adDate, adDouble, adCurrency, adSmallInt
tbl.Columns.Append Name, DataType
If Auto Then tbl.Columns(Name).Properties("AutoIncrement") = True
tbl.Columns(Name).Properties("Nullable") = True
Case adBoolean
tbl.Columns.Append Name, DataType
Case adWChar
tbl.Columns.Append Name, DataType, FieldLenght
tbl.Columns(Name).Properties("Jet OLEDB:Allow Zero Length") = True
tbl.Columns(Name).Properties("Nullable") = True
Case adLongVarWChar, adLongVarBinary
tbl.Columns.Append Name, DataType
tbl.Columns(Name).Properties("Jet OLEDB:Allow Zero Length") = True
tbl.Columns(Name).Properties("Nullable") = True
End Select
End Sub
oh1mie/Vic

-
Feb 20th, 2002, 05:21 AM
#4
Frenzied Member
Here is code to add new column to table with ADOX
Code:
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim Col As New ADOX.Column
cat.ActiveConnection = strConnectCommand & _
DbFile & ";"
Col.name = FieldName
Col.Attributes = adColNullable
If Pituus > 0 Then Col.DefinedSize = FieldLenght
Col.Type = FieldStyle
cat.Tables.item(Mytable).Columns.Append Col
cat.Tables.item(Mytable).Columns.item(FieldName).Properties("Jet OLEDB:Allow Zero Length") = True
Set cat = Nothing
oh1mie/Vic

-
Feb 20th, 2002, 05:25 AM
#5
Frenzied Member
Sorry there if one word, what need little bit explanation.
If Pituus > 0 Then Col.DefinedSize = FieldLenght
Id did cut this code from my project and word "Pituus" is finnish and mean lenght. It's optional parameter what is given to sub
oh1mie/Vic

-
Feb 21st, 2002, 12:33 AM
#6
Thread Starter
Junior Member
-
Feb 21st, 2002, 03:05 AM
#7
Frenzied Member
Originally posted by Roshec
Thanks for the code snippet oh1mie
I'm having trouble with this:
tbl.Columns(Name).Properties("Nullable") = True
......
Use on proserude:
Code:
On local error Resume next
It passing lines what not able to field style
oh1mie/Vic

-
Feb 21st, 2002, 07:19 PM
#8
Thread Starter
Junior Member
Thanks again oh1mie...but I just copied your snippet and it's still giving me problems...
Case adInteger, adDate, adDouble, adCurrency, adSmallInt
Tempfield.Properties("Nullable") = True
Case adVarWChar, adLongVarWChar, adLongVarBinary
Tempfield.Properties("Jet OLEDB:Allow Zero Length") = True
Tempfield.Properties("Nullable") = True
-
Feb 22nd, 2002, 02:30 AM
#9
Frenzied Member
Propably you must update your ADO referenses
Do you have a latest MDACs ?
Install allso Microsofts MS Jet 4.0 Service Pack 3
oh1mie/Vic

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|