Click to open or copy the DYNABIND project files.
DYNABIND illustrates dynamic binding of database columns to a record set.
It is easier to bind columns to members of a record set, using ClassWizard, if you have access to the column information in an open database connectivity (ODBC) data source at the time you develop and compile the program. In some advanced database applications, however, not all of the columns are necessarily known at development and compile time.
For example, a vertical database application, such as for grocery store inventory, would have predefined tables and columns describing the details of grocery inventory. This application might also offer a customization feature that allows the end user (for example, the customer site database administrator) to define additional tables or columns. In this case, the application needs to be implemented in a more general table-driven fashion, to some extent like a general-purpose fourth-generation language (4GL) database system.
DYNABIND illustrates this by adding a customization feature to Step 3 of the database tutorial sample ENROLL. DYNABIND allows the user to add one or more text fields to the Section form. The fields may correspond to columns in the Section table of the Student Registration database that were not necessarily defined at the time that the CSectionSet
class was originally created by ClassWizard.
DYNABIND has the same user interface as that of ENROLL Step 3, except for the addition of the customization feature. The Add Fields command in the Options menu lets you add fields to the bottom of the Section form. The Add Text Field dialog box lists all of the text columns (SQL_CHAR and SQL_VARCHAR) of the Section table of the Student Registration database that have not been previously dynamically added. From the list box, select the column you want to dynamically add to the form, and choose OK. DYNABIND will add an edit control to the bottom of the Section form. You then can enter data in this new form field, just as for any of the other prebound fields.
Note DYNABIND does not save the list of dynamically bound columns when you exit. DYNABIND only supports dynamic binding of the SQL_CHAR and SQL_VARCHAR data types. DYNABIND does not define new columns in the database. Use the existing columns already defined in the Section table, or use Microsoft Query or Microsoft Access to add columns to the Section table.
This sample demonstrates the following keywords:
AfxMessageBox; AfxThrowDBException; CComboBox::AddString; CComboBox::GetCurSel; CComboBox::GetLBText; CComboBox::ResetContent; CComboBox::SetCurSel; CDialog::DoModal; CDialog::OnInitDialog; CDocument::OnNewDocument; CEdit::Create; CEdit::SetReadOnly; CFieldExchange::SetFieldType; CListBox::AddString; CListBox::SetCurSel; CListBox::SetSel; CObList::AddTail; CObList::GetCount; CObList::IsEmpty; CObject::AssertValid; CObject::Dump; CRecordView::OnGetRecordset; CRecordView::OnMove; CRecordset::AddNew; CRecordset::Close; CRecordset::Delete; CRecordset::DoFieldExchange; CRecordset::GetDefaultConnect; CRecordset::GetDefaultSQL; CRecordset::GetTableName; CRecordset::IsBOF; CRecordset::IsEOF; CRecordset::IsOpen; CRecordset::Move; CRecordset::MoveFirst; CRecordset::MoveLast; CRecordset::MoveNext; CRecordset::OnSetOptions; CRecordset::Open; CRecordset::Requery; CRecordset::SetFieldNull; CRecordset::Update; CScrollView::GetTotalSize; CScrollView::ResizeParentToFit; CScrollView::SetScrollSizes; CStatic::Create; CStatusBar::Create; CStatusBar::SetIndicators; CString::Empty; CString::IsEmpty; CToolBar::Create; CToolBar::LoadBitmap; CToolBar::SetButtons; CView::DoPreparePrinting; CView::GetDocument; CView::OnBeginPrinting; CView::OnEndPrinting; CView::OnInitialUpdate; CView::OnPreparePrinting; CWinApp::AddDocTemplate; CWinApp::Enable3dControls; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::OnFileNew; CWnd::DoDataExchange; CWnd::GetFont; CWnd::GetParentFrame; CWnd::GetWindowRect; CWnd::OnCreate; CWnd::ScreenToClient; CWnd::SetFont; CWnd::UpdateData; afxTraceFlags