DateTime with ODBC
If using ODBC & date/time fields in a typical CRecordView, ClassWizard automatically binds a CTime object to the specific recordset. This object has few limits, but the most important is: there is no way to attach an Edit control in a CRecordView to that field.
With this code, it is possible to bind a date/time field to an Edit control using all MFC utilities, just like string parsing, data validation, data automatic set/get and so on.
To implement this function you have to do following steps:
1. Add date.h & date.cpp to your project
2. #include "date.h" in your CMyRecordView.cpp
3. Modify CMyRecordView::DoDataExchange( CDataExchange* pDX) as following
void CMyRecordView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEsamiObiettiviView)
DDX_FieldText(pDX, IDC_EDT_NOTE, m_pSet->m_Note, m_pSet);
DDV_MaxChars(pDX, m_pSet->m_Note, 256);
...
...
//}}AFX_DATA_MAP
DDX_FieldDate( pDX, IDC_EDT_DATE, m_pSet->m_Date, m_pSet );
}
4. Modify CMyRecordSet as follows:
CTime m_Date becomes TIMESTAMP_STRUCT m_Date
5. Find CMyOwnApp::InitInstance() and add setlocale( LC_ALL, ".OCP" ) This function helps you to use the ControlPanel setup for date & time representations (don't forget to #include "locale.h").
6. That's all!
Reading the date.cpp it is possible to find three important functions:
DDX_FieldDate(...) GetDate(...) SetDate(...)This is an easy way to create your own bind method with a particular control & table fields: DDX_FieldsXYZ executes the controls; GetXYZ retrieves data from your control (don't forget to create a validation routine) and SetXYZ displays data in the format you prefer.
Following source contains two functions DDX_FieldDate for date only, and DDX_FieldDateTime for date and time too.
I test it only on Access DB via ODBC, could someone tests this code with SQLServer or other DBServer (via ODBC too)?
Date Last Updated: April 3, 1999

Comments
this also works with sql server
Posted by sharma_shlabh on 05/23/2005 05:41amthis is a very good code works well with sql server
Replylinking Excel Driver to Visual C++
Posted by Legacy on 06/16/2003 12:00amOriginally posted by: Steve
My Problem is, i have an excel driver set up in odbc, but when i try and link it to my Visual C++ (MFC) project through the setup steps i cant add a table like when using Access, does anybody know the base class or what i have to do to set up, (CRecordSet doesnt work, or i cant figure out how to use it with .xls!!!) im trying to read and write to the database!!
Thanks in advance,
ReplySteve:o)
how define time field in DAO and how write date of system on that field
Posted by Legacy on 03/02/2003 12:00amOriginally posted by: ASHKAN
Dear sir,
ReplyI create a *.mdb file with DAO but I can not write date of system in one field of database record. In other word I dont know how define time field in DAO and how write date of system on that field.Please help me with a source file
thanks in advance,
sincerely yours,
how define time field in DAO and how write date of system on that field
Posted by Legacy on 03/02/2003 12:00amOriginally posted by: ASHKAN
Dear sir,
ReplyI create a *.mdb file with DAO but I can not write date of system in one field of database record. In other word I dont know how define time field in DAO and how write date of system on that field.Please help me with a source file
thanks in advance,
sincerely yours,
how define time field in DAO and how write date of system on that field
Posted by Legacy on 03/02/2003 12:00amOriginally posted by: ASHKAN
Dear sir,
ReplyI create a *.mdb file with DAO but I can not write date of system in one field of database record. In other word I dont know how define time field in DAO and how write date of system on that field.Please help me with a source file
thanks in advance,
sincerely yours,
what is TIMESTAMP_STRUCT?error occur!
Posted by Legacy on 08/15/2002 12:00amOriginally posted by: blue
I do as the step you said,but many errors occur because
Replythe TIMESTAMP_STRUCT structure ?what is TIMESTAMP_STRUCT?
May I include any head file(s)?thank you!
Invert lines for empty date
Posted by Legacy on 07/12/2002 12:00amOriginally posted by: Emilie
ReplyGreat!!
Posted by Legacy on 03/07/2002 12:00amOriginally posted by: Bart
Thnx a lot! Just what I needed, works fine....
Reply
C++ Takes it up the ass
Posted by Legacy on 11/01/2001 12:00amOriginally posted by: Cameron
Just wanted to say that programming takes it up the ass
ReplyDTX - Database Toolbox For MFC 1.8
Posted by Legacy on 08/18/2001 12:00amOriginally posted by: anonymous
DTX - Database Toolbox For MFC 1.8 is a good complete database application framework. Use DAO and ADO. Including DTXDAoTable, DTXADOTable, DBEdit, DBNavigator, DBGrid, DBImage, Calculator, Calculator edit, DBRichEdit, DBListCtrl, etc. ~70+ ready to use class. Try this now including Release version
homepage:
http://server33.hypermart.net/celibol
DTX homePage:
http://server33.hypermart.net/celibol/dtx.html
Download link
http://server33.hypermart.net/celibol/dtx.zip
Reply
Loading, Please Wait ...