Re: ADOX - Access table creation with nullable columns.




"Andy" <Andy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8D280F5B-F6A9-4618-9782-32D923D86E49@xxxxxxxxxxxxxxxx
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.



Ok, I think I got it now. <g>

You want to add a Column to an existing Table in MSAccess. You can append th
e column, but not set its attribute to Nullable.

If you follow the examples by setting it before appending - there is no
error, but the column attribute doesn't get set either. Correct?
If you try appending the column, and then go back and set the Attribute -
you get an error. Correct?

It looks to me like it should work. (Duh! That's what this is all about.
<bg>)
What provider are you using to initially connect to the database? ie, what's
the create string look like? (The provider is almost always at the root of
"strange behavior".) What the MDB file format you using? Or provide the
code.

I'll try and see if I can duplicate your problem with VC++.

What I posted does work with classic VB.

-ralph




.