Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I bind dtpicker to oracle

Posted on 2004-10-16
5
Medium Priority
?
476 Views
Last Modified: 2013-11-20
I want to bind datetimepicker control to oracle database
0
Comment
Question by:vijay_visana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:nabehs
ID: 12331526
can you give more information? I can help, but do you need to populate the edit box of the datetime picker with a value from the database?
0
 
LVL 7

Author Comment

by:vijay_visana
ID: 12337124
yes I want to poulate editboox of dtpicker from date stored in oracle table as well as save the changed one back to oracle table
0
 
LVL 6

Accepted Solution

by:
nabehs earned 1500 total points
ID: 12355458
1. In Class View, Right Click, New Class. From the Dialog Combo, select Generic Class, Enter the name CQuery1 and press OK. A new class is created with query1.cpp and query1.h files
2. Open query1.h file
3. Assume that you have the table Users with the following fields
mydate : date

4. Modify the class CQuery1 in query1.h to the following
class CQuery1
{
public:
    CQuery1();
    virtual ~CQuery1();

    DBTIMESTAMP m_mydate;

BEGIN_COLUMN_MAP(CQuery1)
    COLUMN_ENTRY(1, m_mydate)
END_COLUMN_MAP( )
};

5. In stdafx.h add the following line:
#include <atldbcli.h>

6. Add the following function to get and save the date

#include "query1.h"
void GetMyDate(CSession& session, CString& strKeyCol, CString& strMyDate);
void SaveMyDate(CSession& session, CString& strKeyCol, CString& strMyDate);

void GetMyDate(CSession& session, CString& strKeyCol, CString& strMyDate)
{
    CoInitialize(NULL);

    CCommand<CAccessor<CQuery1> > rs;

      HRESULT hr;

    CString strQuery;
    strQuery.Format("SELECT mydate FROM mytable WHERE keycolumn = '%s'", LPCTSTR(strKeyCol));
    // without error checking
    hr = rs.Open(session, LPCTSTR(strQuery));
      if(rs.MoveNext() == S_OK)
      {
            COleDateTime dt(rs.m_mydate.year, rs.m_mydate.month, rs.m_mydate.day,
            rs.m_mydate.hour, rs.m_mydate.minute, rs.m_mydate.second);
            strMyDate = dt.Format("%m/%d/%Y");
      }

      rs.Close();

    CoUninitialize( );
}

void SaveMyDate(CSession& session, CString& strKeyCol, CString& strMyDate)
{
    CoInitialize(NULL);

    CCommand<CNoAccessor, CNoRowset> cmd;

      HRESULT hr;

    CString strQuery;
    strQuery.Format("UPDATE mytable SET mydate = '%s' WHERE keycolumn = '%s'", LPCTSTR(strMyDate), LPCTSTR(strKeyCol));
    // without error checking
    hr = cmd.Open(session, LPCTSTR(strQuery), NULL, NULL, DBGUID_SQL, false);

      cmd.Close();

    CoUninitialize( );
}

7. add the following data member to the class
CDataSource m_ds;
CSession m_session;

8. Open the connection at program start

      CoInitialize(NULL);

    CString strConnectionString = "Provider=MSDAORA.1;Data Source=MyDatabase;User Id=userid;Password=userpassword;";
    // Replace MyDatabase with your database name
    // Replace userid with the user id
    // Replace userpassword with password

    HRESULT hr;

    // without error checking
    hr = m_ds.OpenFromInitializationString(strConnectionString.AllocSysString( ));
    hr = m_session.Open(m_ds);

9. on dialog start fill the datetime picker with the value from the database by calling GetMyDate by passing m_session as the first parameter

10. on lost focus of the datetime picker save the value to the database by calling SaveMyDate by passing m_session as the first parameter

11. On program end, close the session and connection
m_session.Close();
m_ds.Close();
0
 
LVL 7

Author Comment

by:vijay_visana
ID: 12356272
thnx nabehs
I'll try it and let u know about it
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question