在VC++中做控件与数据表字段绑定

 做管理系统难免与数据库打交道……我们都要将控件与数据表中的字读绑定……在VC++ 6.0中,提供了MFC ClassWizard,这很方便的就能实现这一功能……但是在VC++ 2008中,却去掉了ClassWizard这个功能……所以,这里就不那么方便了……

然而了解原理的都知道,这不过就是添加几个代码就搞定了事……

DDX_FieldText函数就是解决之道……

 

void AFXAPI DDX_FieldText(CDataExchange* pDX,   int nIDC,   COleCurrency& value,   CDaoRecordset* pRecordset);

pDX

A pointer to a CDataExchange object. The framework supplies this object to establish the context of the data exchange, including its direction.

nIDC

The ID of a control in the CRecordView or CDaoRecordView object.

value

A reference to a field data member in the associated CRecordset or CDaoRecordset object. The data type of value depends on which of the overloaded versions of DDX_FieldText you use.

pRecordset

A pointer to the CRecordset or CDaoRecordset object with which data is exchanged. This pointer enables DDX_FieldText to detect and set Null values.

例:

void CMyDaoRecordView::DoDataExchange(CDataExchange* pDX)
{
   CDaoRecordView::DoDataExchange(pDX);
   DDX_FieldCBString(pDX, IDC_LASTNAME, m_pSet->m_LastName, m_pSet);
   DDX_FieldText(pDX, IDC_ID, m_pSet->m_EmployeeID, m_pSet);
   DDX_FieldText(pDX, IDC_AGE, m_pSet->m_Age, m_pSet);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值