Re: Create a multi-column primary key from C++
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Thu, 10 Apr 2008 15:11:18 -0400
theunissen@xxxxxxxxxxx wrote:
On Apr 10, 10:16 am, "Bob Barrows [MVP]" <reb01...@xxxxxxxxxxxxxxx>--
wrote:
theunis...@xxxxxxxxxxx wrote:
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.
--------------------------------------------------------------------
Thanks,
--------------------> 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;
An additional problem is that it needs to work for both: MSACCESS and
SQL Server. So I probably cannot use TSQL statements and have to do
everything through ADO and ADOX.
I was afraid of that. Obviously you don't want to have to write separate
code for each backend.
All the examples show Visual Basic code, which is much easier to use,
and some of the functionality is done 'under-the-hood', which is
probably what causes my problems since I cannot see or figure out how
to do it.
Well, I don't do C++, but looking at your example, I don't see the
attempt to add a second column to the key. I would think you would be
passing Null or Nothing (not sure which) rather than empty strings to
the optional arguments
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
.
- Follow-Ups:
- Re: Create a multi-column primary key from C++
- From: theunissen
- Re: Create a multi-column primary key from C++
- References:
- Create a multi-column primary key from C++
- From: theunissen
- Re: Create a multi-column primary key from C++
- From: Bob Barrows [MVP]
- Re: Create a multi-column primary key from C++
- From: theunissen
- Create a multi-column primary key from C++
- Prev by Date: Re: Create a multi-column primary key from C++
- Next by Date: Re: Create a multi-column primary key from C++
- Previous by thread: Re: Create a multi-column primary key from C++
- Next by thread: Re: Create a multi-column primary key from C++
- Index(es):
Relevant Pages
|
|