简体   繁体   English

如何使用C ++获取MS Access数据库列的默认值?

[英]How to get the default value of a column of MS Access Database using C++?

This is the sql script I used to create a table in MS Access Database. 这是我用来在MS Access数据库中创建表的sql脚本。

CREATE TABLE Contracts (
id int  NULL DEFAULT 0,
sex varchar(255) DEFAULT 'female' NOT NULL
)

Now I want to programmatically get the default value of the field: "sex", I know it's 'female' but I don't know how to get it using C++ ADO interface. 现在,我想以编程方式获取该字段的默认值:“性别”,我知道它是“女性”,但我不知道如何使用C ++ ADO接口获取它。

Below is a snippet of my code: 以下是我的代码片段:

m_pRecordset->Fields->get_Item(vIntegerType, &pvObject);
bstrColName = pvObject->GetName();
dtype = pvObject->GetType();
attr = pvObject->GetAttributes();

I can give you idea how to achieve it.. 我可以告诉你如何实现它。

GetAttributes() method will not give you default value of the field but it will give you info about whether field is autoincrement ,system field or fixed - variable size field. GetAttributes()方法不会为您提供该字段的默认值,但会为您提供有关该字段是autoincrement,系统字段还是固定大小可变字段的信息。

Check out for method GetDefaultValue() of the field that will do what you want. 出将执行所需操作的字段的方法GetDefaultValue()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM