在VC++中做控件与数据表字段绑定
2008-10-12 12:13
344 查看
做管理系统难免与数据库打交道……我们都要将控件与数据表中的字读绑定……在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.
例:
然而了解原理的都知道,这不过就是添加几个代码就搞定了事……
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); }
相关文章推荐
- 地磅称量系统之(37~39) 直接向数据库的数据表WtBill添加测试数据以及绑定用户控件和使用编码的方式控制dataGridView控件的每列属性和添加数据数据库的表中不存在的字段(非绑定列)
- 在数据绑定控件的DataBound事件中获取某绑定字段值
- 通过属性编辑器灵活调整数据控件的绑定字段
- 如何将数据库中的字段数据绑定显示在Label或TextBox控件中
- .net关于控件绑定字段的数据类型
- 数据绑定控件的ItemDataBound事件中怎么得到数据库字段的值
- GridView 动态添加模板列并绑定数据 实现从外部直接传入控件 和 绑定字段参数
- 将数据表相关字段绑定到DropDownList控件
- 数据绑定控件Repeater/GridView/DataList在前台显示正确的文本格式收藏
- 将ComboBox 控件绑定到数据
- 数据绑定控件 优缺点分析
- 数据绑定控件ListView
- 数据绑定和数据网格视图(DataGridView)控件
- WPF 数据控件绑定数据与 ASP.NET数据控件绑定数据的区别
- Asp.net--数据绑定控件DataList
- 从XML文件读取数据绑定到列表控件2
- 数据源控件如何为数据绑定字段创建参数
- 晚上 总结 一下数据绑定控件
- asp.net学习之 数据绑定控件--表格绑定控件
- 如何让GridView控件在绑定的数据源没有数据时也显示标题