您的位置:首页 > 编程语言

一小段利用adox获取表结构主键字段的代码

2005-07-08 14:32 417 查看
#import "c:/Program Files/Common Files/system/ado/msadox.dll" no_namespace
#import "c:/Program Files/Common Files/system/ado/msado15.dll"
#include <stdio.h>
int main()
{
if(FAILED(::CoInitialize(NULL)))
return 1;
_CatalogPtr pCatalog = NULL;
_bstr_t strcnn("Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;"
"User ID=sa;Initial Catalog=pubs;Data Source=server");
pCatalog.CreateInstance(__uuidof (Catalog));
pCatalog->PutActiveConnection(strcnn);
_variant_t varIndex((long)-1);
_KeyPtr pKey = NULL;
KeyTypeEnum enumKey ;
try
{
while (1)//i don't how to decide the key's cnt,so just make a throw error
{
++varIndex.llVal;
pKey = pCatalog->Tables->GetItem("titleauthor")->Keys->GetItem(varIndex);
static const char *KEYDESC [] = {"adKeyPrimary ","adKeyForeign ","adKeyUnique "};
enumKey = pKey->GetType ();
printf("%s/t%d/t%s/r/n",(char*)pKey->GetName (),enumKey,KEYDESC[enumKey-1]);
}
}
catch(...)
{
}
::CoUninitialize();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐