Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Data Exchange

Data Exchange

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasetutorialannouncement
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PJ ArendsP PJ Arends

    shouvik.d wrote:

    The basic prob is how to update data without closing the Dlg Box.

    Use a modeless dialog. http://msdn2.microsoft.com/en-us/library/hf0yazk7(vs.80).aspx[^]


    You may be right
    I may be crazy
    -- Billy Joel --

    Within you lies the power for good, use it!!!

    S Offline
    S Offline
    Shouvik Das
    wrote on last edited by
    #3

    No i cant let a user access the SDI window when he/she is accessing the Dlg Box. I just used DDX but still until the Modal Dlg Box Closes I'm not able to invoke update to DB. how to do it:confused:

    Success makes life easier. It doesn't make living easier. SH:)UVIK

    C 1 Reply Last reply
    0
    • PJ ArendsP PJ Arends

      shouvik.d wrote:

      The basic prob is how to update data without closing the Dlg Box.

      Use a modeless dialog. http://msdn2.microsoft.com/en-us/library/hf0yazk7(vs.80).aspx[^]


      You may be right
      I may be crazy
      -- Billy Joel --

      Within you lies the power for good, use it!!!

      S Offline
      S Offline
      Shouvik Das
      wrote on last edited by
      #4

      This is what when the admin module has to be invoked. A passsword validation is done. Later the Admin window opens.

      void CLibManView::OnAdmin() 
      {
      	Pass p1;
      	p1.DoModal();
      	CString str,query,str1;
      	int flag = 0;
      	str=p1.m_pass;
      	
      	m_pSet->Close();
      	query = "Select * from Password where User='Admin'";
      	m_pSet->Open(CRecordset::dynaset, (LPCTSTR)query,CRecordset::none);
      	m_pSet->MoveFirst();
      	while(!m_pSet->IsEOF())
      	{
      		str1=m_pSet->m_Pass;
      		if(str1==str)
      		{
      			flag=1;
      			break;
      		}
      		m_pSet->MoveNext();
      	}
      	if(0==flag)
      		MessageBox("Wrong Password");
      	else
      	{
      		ad.DoModal();
      		m_pSet->Close();
      		char temp[2];
      		itoa(ad.type,temp,2);
      	         char locstat[2];
      		itoa(2,locstat,2);
      		query="insert into book values('"+ad.m_Auto_Ac_No+"','"+ad.m_Add_Name+"','"+ad.m_Add_Auth+"',"+temp+","+ad.m_Add_Price+",'"+ad.m_Add_Date+"',"+locstat+")";
      		m_pSet->Open(CRecordset::dynaset,(LPCTSTR)query,CRecordset::none);
      		m_pSet->Update();
      		m_pSet->Close();
      	}
      }
      

      So without closing the Admin dlg box how to update data. also i'm getting an error. Syntax error in FROM clause on the above query. plz help


      Man can acquire accomplishments or he can become an animal, whichever he wants. God makes the animals, man makes himself. G. C. Lichtenberg (1742-99), German physicist, philosopher. SH:)UVIK

      PJ ArendsP 1 Reply Last reply
      0
      • S Shouvik Das

        No i cant let a user access the SDI window when he/she is accessing the Dlg Box. I just used DDX but still until the Modal Dlg Box Closes I'm not able to invoke update to DB. how to do it:confused:

        Success makes life easier. It doesn't make living easier. SH:)UVIK

        C Offline
        C Offline
        Cristian Amarie
        wrote on last edited by
        #5

        shouvik.d wrote:

        No i cant let a user access the SDI window when he/she is accessing the Dlg Box.

        Disable the SDI window while the dialog box is active. MFC simulates modal dialog boxes exactly in this way, creating a modeless dialog box from template, disabling main window if any, display the dialog, and reenable the main window after. Another possibility is to inform application from the modal dialog to perform the update. This way you don't have to wait the dialog to close, such as in

        void CDlg::OnButtonClicked()
        {
        // gather data to update in a structure or class
        CData data;
        // ...

        static_cast(AfxGetApp())->updateDatabase(&data);
        }

        and

        void CSDIApp::updateDatabase(CData *pData)
        {
        // update in database using pData members
        }

        S 1 Reply Last reply
        0
        • PJ ArendsP PJ Arends

          shouvik.d wrote:

          The basic prob is how to update data without closing the Dlg Box.

          Use a modeless dialog. http://msdn2.microsoft.com/en-us/library/hf0yazk7(vs.80).aspx[^]


          You may be right
          I may be crazy
          -- Billy Joel --

          Within you lies the power for good, use it!!!

          S Offline
          S Offline
          Shouvik Das
          wrote on last edited by
          #6

          plz help


          Man can acquire accomplishments or he can become an animal, whichever he wants. God makes the animals, man makes himself. G. C. Lichtenberg (1742-99), German physicist, philosopher. SH:)UVIK

          C 1 Reply Last reply
          0
          • S Shouvik Das

            This is what when the admin module has to be invoked. A passsword validation is done. Later the Admin window opens.

            void CLibManView::OnAdmin() 
            {
            	Pass p1;
            	p1.DoModal();
            	CString str,query,str1;
            	int flag = 0;
            	str=p1.m_pass;
            	
            	m_pSet->Close();
            	query = "Select * from Password where User='Admin'";
            	m_pSet->Open(CRecordset::dynaset, (LPCTSTR)query,CRecordset::none);
            	m_pSet->MoveFirst();
            	while(!m_pSet->IsEOF())
            	{
            		str1=m_pSet->m_Pass;
            		if(str1==str)
            		{
            			flag=1;
            			break;
            		}
            		m_pSet->MoveNext();
            	}
            	if(0==flag)
            		MessageBox("Wrong Password");
            	else
            	{
            		ad.DoModal();
            		m_pSet->Close();
            		char temp[2];
            		itoa(ad.type,temp,2);
            	         char locstat[2];
            		itoa(2,locstat,2);
            		query="insert into book values('"+ad.m_Auto_Ac_No+"','"+ad.m_Add_Name+"','"+ad.m_Add_Auth+"',"+temp+","+ad.m_Add_Price+",'"+ad.m_Add_Date+"',"+locstat+")";
            		m_pSet->Open(CRecordset::dynaset,(LPCTSTR)query,CRecordset::none);
            		m_pSet->Update();
            		m_pSet->Close();
            	}
            }
            

            So without closing the Admin dlg box how to update data. also i'm getting an error. Syntax error in FROM clause on the above query. plz help


            Man can acquire accomplishments or he can become an animal, whichever he wants. God makes the animals, man makes himself. G. C. Lichtenberg (1742-99), German physicist, philosopher. SH:)UVIK

            PJ ArendsP Offline
            PJ ArendsP Offline
            PJ Arends
            wrote on last edited by
            #7

            One method is to do what Cristian Amarie said above. Another is to move the SQL code into the dialog itself.


            You may be right
            I may be crazy
            -- Billy Joel --

            Within you lies the power for good, use it!!!

            Within you lies the power for good; Use it!

            S 1 Reply Last reply
            0
            • C Cristian Amarie

              shouvik.d wrote:

              No i cant let a user access the SDI window when he/she is accessing the Dlg Box.

              Disable the SDI window while the dialog box is active. MFC simulates modal dialog boxes exactly in this way, creating a modeless dialog box from template, disabling main window if any, display the dialog, and reenable the main window after. Another possibility is to inform application from the modal dialog to perform the update. This way you don't have to wait the dialog to close, such as in

              void CDlg::OnButtonClicked()
              {
              // gather data to update in a structure or class
              CData data;
              // ...

              static_cast(AfxGetApp())->updateDatabase(&data);
              }

              and

              void CSDIApp::updateDatabase(CData *pData)
              {
              // update in database using pData members
              }

              S Offline
              S Offline
              Shouvik Das
              wrote on last edited by
              #8

              firstly thr is no CData class only CDatabase is available. and plz can u throw a bit more light into this. I'm an amateur n very new to VC++.


              There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK

              C 1 Reply Last reply
              0
              • PJ ArendsP PJ Arends

                One method is to do what Cristian Amarie said above. Another is to move the SQL code into the dialog itself.


                You may be right
                I may be crazy
                -- Billy Joel --

                Within you lies the power for good, use it!!!

                S Offline
                S Offline
                Shouvik Das
                wrote on last edited by
                #9

                But i am not able to access the m_pSet-> variable in the Dialog Box. So how can i update the fields which can be accessed through only the REcordset object m_pSet.


                There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK

                PJ ArendsP 1 Reply Last reply
                0
                • S Shouvik Das

                  firstly thr is no CData class only CDatabase is available. and plz can u throw a bit more light into this. I'm an amateur n very new to VC++.


                  There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK

                  C Offline
                  C Offline
                  Cristian Amarie
                  wrote on last edited by
                  #10

                  I mean CData as a placeholder for your data, you should implement it yourself as a mean to communicate between the dialog and the application object. In this way, you can collect data from the dialog, declare and fill a structure or class (this is CData) and pass it to the application (or whatever other object you want to delegate for operating in database).

                  1 Reply Last reply
                  0
                  • S Shouvik Das

                    But i am not able to access the m_pSet-> variable in the Dialog Box. So how can i update the fields which can be accessed through only the REcordset object m_pSet.


                    There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) SH:)UVIK

                    PJ ArendsP Offline
                    PJ ArendsP Offline
                    PJ Arends
                    wrote on last edited by
                    #11

                    You can pass the m_pSet pointer to your dialog class when you start the dialog.


                    You may be right
                    I may be crazy
                    -- Billy Joel --

                    Within you lies the power for good, use it!!!

                    Within you lies the power for good; Use it!

                    1 Reply Last reply
                    0
                    • S Shouvik Das

                      plz help


                      Man can acquire accomplishments or he can become an animal, whichever he wants. God makes the animals, man makes himself. G. C. Lichtenberg (1742-99), German physicist, philosopher. SH:)UVIK

                      C Offline
                      C Offline
                      Cristian Amarie
                      wrote on last edited by
                      #12

                      You got the help already. 1. Pass the database objects as pointers (or references) to the dialog and do the DB work directly inside dialog. 2. Use a messaging mechanism (not especially Windows messages, although could work too) to signal back from dialog to the object that contain your variable m_pRecSet to "do the DB work". 3. Use a separate class that does the DB work, declared by the application object, main window object or where you see this fit, and use a messaging mechanism back and forth to/from this object to any object that require "DB services". Whenever a DB operation needs to be performed, you must have the means to retrieve and use the DB object, either directly (1), via accesors of other objects (2), or using a convenient object that encapsulates the DB services (3). The solution is up to you, as well as what kind of services can be performed - direct brute queries formatted elsewhere, or using more specialized business logic oriented derived classes. I suggest you to implement a hierarchy like: Connection  Statement   StatementWithResults    Recordset    StoredProcedure    ... (whatever you like) as well as your business objects which can derive from StatementWithResults (1 row in a table) or Recordset for collections.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups