Hi,
I am using SQL Server 2005 Express and I am able to create a primary
key using the following code in Visual C++ 2005:
------------------------------------------------------------------------------------------
m_pTable->Keys->Append("MyKey", ADOX::adKeyPrimary, "Label", _T(""),
_T(""));
------------------------------------------------------------------------------------------
"Label" is the name of the column that should contain the primary key.
Hwoever, when I want to create a multi-column key hopwever, an
exception is thrown telling me that the parameters are incorrect. The
folowing code show how I am creating the multi-column key. The fail
occors in the append function.
------------------------------------------------------------------------------------------
ADOX::_KeyPtr m_pKey = NULL;
m_pKey.CreateInstance(__uuidof(ADOX::Key));
m_pKey->PutName("MyKey");
m_pKey->PutType(ADOX::adKeyPrimary);
m_pKey->Columns->Append("Label", ADOX::adVarChar, 255);
Table.m_pTable->Keys->Append(_variant_t((IDispatch *) m_pKey),
ADOX::adKeyPrimary, "", "", "");
m_pKey.Release();
m_pKey = NULL;
------------------------------------------------------------------------------------------
I have no clue what I'm doing wrong. It might have todo with the
optional parameters in the append method. Though I think they are just
optional since I'm passing a Key object, so it shouldn't matter what
you specify in C++.
Any help would be appreciated.
Michel


|