Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Software > ADO Data > Create a multi-...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 4206 of 4320
Post > Topic >>

Create a multi-column primary key from C++

by theunissen@[EMAIL PROTECTED] Apr 10, 2008 at 09:41 AM

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
 




 5 Posts in Topic:
Create a multi-column primary key from C++
theunissen@[EMAIL PROTECT  2008-04-10 09:41:45 
Re: Create a multi-column primary key from C++
"Bob Barrows [MVP]&q  2008-04-10 13:16:25 
Re: Create a multi-column primary key from C++
theunissen@[EMAIL PROTECT  2008-04-10 10:54:57 
Re: Create a multi-column primary key from C++
"Bob Barrows [MVP]&q  2008-04-10 15:11:18 
Re: Create a multi-column primary key from C++
theunissen@[EMAIL PROTECT  2008-04-10 12:43:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 15:05:56 CST 2008.