In the Code Project's General section - Database area, there is an artical called "The CGeneric Database class". What this does is allow you to use the CGeneric recordset without binding the columns the way Class Wizard does. You can either set/get the column data via the calls like GetBool( "Column Name" ); or GetBool( column number ); This is a Dynamic way to use DAO vs the static way that Class Wizard does it. Also if you add new fields to the table, you don't have to rework the code, just add the new Get/Set routines.
Doug Garno
Posts
-
Access Database Help -
Access Database HelpYour right, ClassWizard doesn't support Jet 4.0 formatted files. Either create the file in Access 97 or you will have to create the record sets and bind them manually. There is another way to do this and use the generic recordset that is posted in the Database section. That is the way I go because I don't like all the recordset files that are required for each table within the file, source code can get quite large.
-
CString to CTimeYou can use COleDateTime::ParseDateTime( string ) to convert the string into the underlying DATE object. If you don't like to use COleDateTime objects and need the CTime object, you would have to convert between the two. Create a tm structure and populate the structure from the COleDateTime object and then using mktime( tm ) assign the result to the CTime object.
-
Converting Jet 3.0 file to Jet 4.0That worked: CDaoWorkspace::CompactDatabase( csOld, csNew, dbLangGeneral, 64 ); I was leaning that way but I thought I would just ask the experts here and save me some time. Thanks for your help.
-
Converting Jet 3.0 file to Jet 4.0Yes you are correct, that is what is required to Open a Jet 4.0 file, but that doesn't convert the file from 3.0 format to 4.0.
-
Converting Jet 3.0 file to Jet 4.0Does anyone know how to convert the Jet 3.0 file into Jet 4.0 format? The CDaoDatabase::CompactDatabase() can only specify dbVersion30 option. Looking at the available options it appears that MFC and DAO hasn't a option for dbVersion40.
-
Making A CStatics Text Go BoldThe problem is in the GetFont() call. MFC wrapps the HFONT in a temporary CFont object and when you call the CreateFontIndirect() a new HFONT is created in the temporary object and never gets back to the control. All you have to do is tell the control to use the new font, GetDlgItem( IDC_TITLE )->SetFont( m_titleFont );
-
Design issueYou have the basic idea. The way that I do it is to pass the list control to the Doc and have the doc populate the list, that way the View doesn't need to know anything about the database. Something like this: CDoc::AddCustomers( CListCtrl* pList ) { // Reset the list control content pList->DeleteAllItems(); // I'm assuming that you somehow get a CDaoRecordset for the Customer table // and not accessing the database object directly. m_MyDaoDB->MoveFirst(); while( m_MyDaoDB->IsEOF() != 0 ) { // Add the record to the list m_MyDaoDB->MoveNext(); } } Don't know if this is a better OO way, but the Doc should know about the data, and the view handles the UI. I like to keep access to the data in the Doc and the View handles the display and user interaction.
-
How to populate a tree controlAh, the basic problem of the parent doesn't know that it has any children attached. Change your tvInsert.mask to include TVIF_CHILDREN and set the tvInsert.cChildren either true or false depending on if the parent has any children. Another way is to create parents with no children, then when you add children to a parent, tell the parent that it now has children. When you add a child to a parent, call a function like UpdateParentItem( HTREEITEM hParent ); void UpdateParentItem( HTREEITEM hParent ) { // Can't use ItemHasChildren() because it will always return // the value of the item.cChildren variable. // Need to get the first child and update the parent as needed. // Getting the first child of a parent will always return either // NULL if no children exist or the handle to the first child // regardless of the item.cChildren variable. HTREEITEM hChild = m_pTree->GetChildItem( hParent ); // Set up the item structure TV_ITEM item; ZeroMemory( &item, sizeof(TV_ITEM) ); item.hItem = hParent; item.mask = TVIF_CHILDREN; item.cChildren = hChild != NULL; // Update the parent node to reflect the children state. m_pTree->SetItem( &item ); } Also make sure that when the tree control is created you set the TVS_HASBUTTONS or you will not see the plus/minus button on the parent. You would have to double click the parent to see if there is any children.
-
CDaoIndexYou do not add an Index to a field, but rather add the index to the CDaoTableDef using the field information. Use CDaoIndexInfo, CDaoIndexFieldInfo to define the index and then use CDaoTableDef::CreateIndex() to create the index in the table definition.
-
Saving and restoring rebar controlDoes anyone know how to save the state of the CReBarCtrl and restore the state of the bands? I've tried to get the band count and then call the CReBarCtrl::GetBandInfo( ... ) but the REBARBANDINFO structure that is returned is no help. Anyone have any ideas?