一小段利用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;
}
#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;
}
相关文章推荐
- 一小段利用adox获取表结构主键字段的代码
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)(轉)
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- 如何获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- 通过jdbc获取数据库中的表结构 主键 各个表字段类型及应用生成实体类
- SQLServer2005,2000获取表结构:字段名、类型、长度、主键、非空、注释
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- Sqlserver获取所有数据库名,表信息,字段信息,主键信息,以及表结构等。
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- 获取SqlServer表结构(字段,主键,外键,递增,描述)
- 如何获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- Oracle获取表结构信息:表名、是否视图、字段名、类型、长度、非空、主键
- 获取表结构信息(字段名,类型,长度,精度,小数位数,主键,自动增长)
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)
- 获取SqlServer2005表结构(字段,主键,外键,递增,描述)