Re: ADOX - Access table creation with nullable columns.
- From: Andy <Andy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 9 Nov 2007 09:26:01 -0800
Unfortunately the original problem still stands ! I can't create a column in
an access database which has the Attributes property
(http://msdn2.microsoft.com/en-us/library/ms681024.aspx) set to
adColNullable.
I've tried two approaches :-
1) As you suggested (based upon
http://msdn2.microsoft.com/en-us/library/ms675314.aspx with bells on - see
first posting). While this allows me to add the column it doesn't actually
set the column to nullable. e.g :-
m_pCol1.CreateInstance(__uuidof(ADOX::Column));
m_pCol1->Name = "Column 1";
m_pCol1->Type = ADOX::adVarWChar;
m_pCol1->DefinedSize = 24;
m_pCol1->Attributes = ADOX::adColNullable; \\Does this work?
m_pTable->Columns->Append(m_pCol1->Name, ADOX::adVarWChar, 24);
2) As Mark suggested. i.e Retrospectively setting the Column's Attribute to
'adColNullable' after it has been Appended to the table. This throws the
"Multi-Step...." exception. e.g :-
//Column has already been appended to table at this point.
//Get table and Columns objects
ADOX::TablesPtr tblsptr;
m_pCatalog->get_Tables(&tblsptr);
ADOX::_TablePtr tblptr = tblsptr->GetItem("MyTable");
ADOX::ColumnsPtr colsptr = tblptr->Columns;
//Get Column
ADOX::_ColumnPtr colptr = colsptr->GetItem("Column 1");
//Set Nullable
colptr->PutAttributes(ADOX::adColNullable); //Fails with MultiStep Error.
I've been tasked with migrating a large vc6.0 project to vc8.0, this
includes removing all deprecated code. The above can be achieved using DAO -
no probs. But now i'm migrating it to ADOX the world has become a very dark
and scary place...I' really stumped here...My guess is that code snippet you
suggested will work in VB but not in VC.
"Ralph" wrote:
.
"Andy" <Andy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C7C7AC4C-53C0-47FB-BA07-E578F4F29AAA@xxxxxxxxxxxxxxxx
Yep, that code was my starting point!. See first post that opened thethread.
Repeated here for clarity :-
.....
m_pCol1.CreateInstance(__uuidof(ADOX::Column));
m_pCol1->Name = "Column 1";
m_pCol1->Type = ADOX::adVarWChar;
m_pCol1->DefinedSize = 24;
m_pCol1->Attributes = ADOX::adColNullable; \\Does this work?
m_pTable->Columns->Append(m_pCol1->Name, ADOX::adVarWChar, 24);
.....
Yeah, I see it NOW, like a bonfire.
[I consider myself a C programmer, but after too many years with VB and
dotNet, I'm not sure I could format a printf statement.]
So what's the question now? I thought the problem was because you were
getting errors trying to use a "Properties Collection" which doesn't support
what you were after. What else is blazing around me that I'm oblivious to.
<g>
-ralph
- Follow-Ups:
- References:
- Re: ADOX - Access table creation with nullable columns.
- From: Ralph
- Re: ADOX - Access table creation with nullable columns.
- From: Ralph
- Re: ADOX - Access table creation with nullable columns.
- From: Andy
- Re: ADOX - Access table creation with nullable columns.
- From: Ralph
- Re: ADOX - Access table creation with nullable columns.
- From: Ralph
- Re: ADOX - Access table creation with nullable columns.
- From: Ralph
- Re: ADOX - Access table creation with nullable columns.
- Prev by Date: Re: Timeout expired (SqlClient.TdsParserStateObject.ReadSniError)
- 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):