Re: ADOX - Access table creation with nullable columns.
- From: Andy <Andy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 12 Nov 2007 04:03:00 -0800
Cracked it!
By default a column does not have a property of Nullable, as (i guess) this
depends on your provider. To work around this I needed to ensure the
ParentCatalog property on the Table was set, before the column is added to
the table. Then after the column is added I could then feret around - find
the Nullable property and set it to true. hurrah! So the steps were :-
1) Create Catalog using chosen provider.
2) Create Table
3) Set Table ParentCatalog property. (New step!)
4) Create Column
5) Append Column to table.
6) Access Column through table object and set Nullable property to true.
7) Append Table to Catalog.
Thanks for all of your help on this. ;o) I've included a new code listing
below.
Andy
New Code listing :-
ADOX::_CatalogPtr m_pCatalog;
ADOX::_TablePtr m_pTable;
ADOX::_ColumnPtr m_pCol1;
ADOX::_ColumnPtr m_pCol2;
ADODB::_ConnectionPtr m_pConn;
ADODB::_RecordsetPtr m_pRs;
//ADOX - Create Data Source
_bstr_t strcnn(("Provider='Microsoft.JET.OLEDB.4.0';Data source =
C:\\test.mdb"));
m_pCatalog.CreateInstance(__uuidof (ADOX::Catalog));
m_pCatalog->Create(strcnn);
m_pTable.CreateInstance(__uuidof(ADOX::Table));
m_pTable->PutName("MyTable");
m_pTable->ParentCatalog = m_pCatalog; //NEW STEP !
m_pCol1.CreateInstance(__uuidof(ADOX::Column));
m_pCol1->Name = "Column 1";
m_pCol1->Type = ADOX::adVarWChar;
m_pCol1->DefinedSize = 24;
m_pTable->Columns->Append(m_pCol1->Name, ADOX::adVarWChar, 24);
m_pTable->Columns->GetItem("Column
1")->Properties->GetItem("Nullable")->Value = true; //SET NULLABLE PROPERTY !
m_pCol2.CreateInstance(__uuidof(ADOX::Column));
m_pCol2->Name = "Column 2";
m_pCol2->Type = ADOX::adVarWChar;
m_pCol2->DefinedSize = 24;
m_pTable->Columns->Append(m_pCol2->Name, ADOX::adVarWChar, 24);
m_pTable->Columns->GetItem("Column
2")->Properties->GetItem("Nullable")->Value = true; //SET NULLABLE PROPERTY !
m_pCatalog->Tables->Append(_variant_t((IDispatch *)m_pTable));
"Bob Barrows [MVP]" wrote:
Ralph wrote:.
"Andy" <Andy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in messagehttp://allenbrowne.com/func-ADOX.html#ModifyFieldPropAdox
news:2E4C90C7-8C7B-482A-B4B0-622CFF47BC19@xxxxxxxxxxxxxxxx
Thanks for the advice. I've tried to access the properties
associated with the Column object and hoped to enumerate through
them to identify their names (Can't find any documentation on what
these are!). I can get a pointer to the properties interface only to
find the property count equals zero. What am I missing here?
VB code may help me - I hope the principles will be the same...
ADOX::_ColumnPtr m_pColumn;
TESTHR(m_pColumn.CreateInstance(__uuidof(ADOX::Column)));
m_pColumn->Name = name;
m_pColumn->Type = nType;
m_pColumn->DefinedSize = lSize;
m_pColumn->Attributes = ADOX::adColNullable;
m_Table->Columns->Append(m_pColumn->Name,nType,lSize);
//Get some properties
ADOX::PropertiesPtr pptr;
m_pColumn->get_Properties(&pptr);
long cnt = pptr->Count; //THIS RETURNS 0 !
Thanks,
Andy
This may or may not help. I often confuse myself when working with
ADOX as it appears to have the same model as ADO, but it is subtly
different. So I may be wrong, but I don't think "Column" has a
property collection in ADOX, except for provider-specific properties.
Your provider may not supply one.
To access existing declared properties (name, type, size, ...) I
think you have to read them one at a time. Just like you set them.
This article seems to imply that there is a properties collection for
columns, and one of the properties provided is called "Nullable".
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
- Follow-Ups:
- References:
- Re: ADOX - Access table creation with nullable columns.
- From: Ralph
- Re: ADOX - Access table creation with nullable columns.
- From: Bob Barrows [MVP]
- Re: ADOX - Access table creation with nullable columns.
- Prev by Date: Re: ADOX - Access table creation with nullable columns.
- Next by Date: Re: ADOX - Access table creation with nullable columns.
- Previous by thread: Re: ADOX - Access table creation with nullable columns.
- Next by thread: Re: ADOX - Access table creation with nullable columns.
- Index(es):
Relevant Pages
|
|