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. MFC vc++ and MySQL database

MFC vc++ and MySQL database

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasemysqltutorial
21 Posts 4 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.
  • D David Crow

    When you derive from a class and override one of its methods, it's common, and sometimes required, to call the base class implementation.

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    M Offline
    M Offline
    Member_14575556
    wrote on last edited by
    #7

    Thanks for the reply. :) If you don't mind, could you please elaborate the "sometime required, to call the base class implementation" part with some example.

    1 Reply Last reply
    0
    • M Member_14575556

      Thanks for the help! I'am having trouble understanding why it does this

      BOOL CMyApp::InitInstance(){
      ..........
      ..........
      CWinApp::InitInsatnce();
      ..........
      ..........
      }

      Could you please explain why do we need to call two InitInstance() and what is the main reason?

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #8

      CMyApp is derived from CWinApp, so the line

      CWinApp::InitInsatnce();

      simply call the InitInstance method from parent CWinApp, which is the base implementation of CMyApp::InitInstance(). "sometime required" sometime is necesarry to call this base implementation, sometime not :)

      M 1 Reply Last reply
      0
      • _ _Flaviu

        CMyApp is derived from CWinApp, so the line

        CWinApp::InitInsatnce();

        simply call the InitInstance method from parent CWinApp, which is the base implementation of CMyApp::InitInstance(). "sometime required" sometime is necesarry to call this base implementation, sometime not :)

        M Offline
        M Offline
        Member_14575556
        wrote on last edited by
        #9

        Thanks :) I am creating a simple MFC application. That has a search box which accept both string and integers to retrieve data from the Mysql database and display in the list box. Please guide me how to create a search box that accepts when entered string and when entered integers.

        L 1 Reply Last reply
        0
        • M Member_14575556

          Thanks :) I am creating a simple MFC application. That has a search box which accept both string and integers to retrieve data from the Mysql database and display in the list box. Please guide me how to create a search box that accepts when entered string and when entered integers.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #10

          Anything you type into a text box is a string, whether letters, numbers or special characters. If you want to use numeric text as integer values then you need to convert them with one of the conversion methods. See Data Conversion | Microsoft Docs[^].

          M 1 Reply Last reply
          0
          • L Lost User

            Anything you type into a text box is a string, whether letters, numbers or special characters. If you want to use numeric text as integer values then you need to convert them with one of the conversion methods. See Data Conversion | Microsoft Docs[^].

            M Offline
            M Offline
            Member_14575556
            wrote on last edited by
            #11

            Thank you for the information :) .

            1 Reply Last reply
            0
            • _ _Flaviu

              You can find here[^] a project sample of how to connect to MySQL database through ODBC ... in fact, to any kind of dababase through ODBC.

              M Offline
              M Offline
              Member_14575556
              wrote on last edited by
              #12

              Hello, I created an MFC dialog application which is connected to MySql database. I wanted to create a search button/Search query for database. Could you give me some pointers for creating functions for the same which accept string as well as Integers. Thanks. I've read about atoi(), but still having problem. And for displaying the search result, which one is better to use listbox or listcontrol.

              _ 1 Reply Last reply
              0
              • M Member_14575556

                Hello, I created an MFC dialog application which is connected to MySql database. I wanted to create a search button/Search query for database. Could you give me some pointers for creating functions for the same which accept string as well as Integers. Thanks. I've read about atoi(), but still having problem. And for displaying the search result, which one is better to use listbox or listcontrol.

                _ Offline
                _ Offline
                _Flaviu
                wrote on last edited by
                #13

                If you have more than one column data to display, I would use CListCtrl[^] or CMFCListCtrl[^] If you want to use an edit to use it for SQL statement, then give more details about what you intend to do there (e.g. sold > 1000 ?)

                M 1 Reply Last reply
                0
                • _ _Flaviu

                  If you have more than one column data to display, I would use CListCtrl[^] or CMFCListCtrl[^] If you want to use an edit to use it for SQL statement, then give more details about what you intend to do there (e.g. sold > 1000 ?)

                  M Offline
                  M Offline
                  Member_14575556
                  wrote on last edited by
                  #14

                  SQl is not greater than 1000. I wanted to create a simple application first. Like for example.. I have a table with ID(primary Key), Name, DOB...etc columns. What I wanted to create is a search box in the dialog application. when I type the Name in the search box it will display the result in the listbox/list control box. Similarly when I enter the ID in the search box it will return the same.

                  _ 1 Reply Last reply
                  0
                  • M Member_14575556

                    SQl is not greater than 1000. I wanted to create a simple application first. Like for example.. I have a table with ID(primary Key), Name, DOB...etc columns. What I wanted to create is a search box in the dialog application. when I type the Name in the search box it will display the result in the listbox/list control box. Similarly when I enter the ID in the search box it will return the same.

                    _ Offline
                    _ Offline
                    _Flaviu
                    wrote on last edited by
                    #15

                    You can use CListCtrl or derivated to display db data. In search box you can test the user input with is_digit[^] and act accordingly (if is number then use ID to get data, or if is not number, use string to get the name and so on.

                    M 1 Reply Last reply
                    0
                    • _ _Flaviu

                      You can use CListCtrl or derivated to display db data. In search box you can test the user input with is_digit[^] and act accordingly (if is number then use ID to get data, or if is not number, use string to get the name and so on.

                      M Offline
                      M Offline
                      Member_14575556
                      wrote on last edited by
                      #16

                      Thank you for always helping. I really appreciate the help :) I have created a search function and now it's displaying in the CListCtrl and working the way I wanted. :) I'll try to extend the functionality like if I select the result in the CListCtrl it will take me to another dialog that contains the details of the selected. :) If I have any doubt i'll post it here. Thanks again :)

                      _ 1 Reply Last reply
                      0
                      • M Member_14575556

                        Thank you for always helping. I really appreciate the help :) I have created a search function and now it's displaying in the CListCtrl and working the way I wanted. :) I'll try to extend the functionality like if I select the result in the CListCtrl it will take me to another dialog that contains the details of the selected. :) If I have any doubt i'll post it here. Thanks again :)

                        _ Offline
                        _ Offline
                        _Flaviu
                        wrote on last edited by
                        #17

                        You are welcome :)

                        M 1 Reply Last reply
                        0
                        • _ _Flaviu

                          You are welcome :)

                          M Offline
                          M Offline
                          Member_14575556
                          wrote on last edited by
                          #18

                          Hello I'm back again :-D How to get all the data present in a row displayed in the ListCtrl from the database and display those data in the next dialog? For example:- There are name, age,dob..etc in a row.. when I select this row and press the select button.. It will take me to another where all this details will be display. If you don't mind could you please give example. Thanks.

                          _ 1 Reply Last reply
                          0
                          • M Member_14575556

                            Hello I'm back again :-D How to get all the data present in a row displayed in the ListCtrl from the database and display those data in the next dialog? For example:- There are name, age,dob..etc in a row.. when I select this row and press the select button.. It will take me to another where all this details will be display. If you don't mind could you please give example. Thanks.

                            _ Offline
                            _ Offline
                            _Flaviu
                            wrote on last edited by
                            #19

                            Then you take all your list control data with CListCtrl::GetItemText[^] and you simply put them into next dialog, just like that:

                            CNextDlg dlg;
                            dlg.m_sName = m_ListCtrl.GetItemText(...);
                            dlg.m_sAge = m_ListCtrl.GetItemText(...);
                            dlg.m_sDOB = m_ListCtrl.GetItemText(...);
                            dlg.DoModal();

                            M 1 Reply Last reply
                            0
                            • _ _Flaviu

                              Then you take all your list control data with CListCtrl::GetItemText[^] and you simply put them into next dialog, just like that:

                              CNextDlg dlg;
                              dlg.m_sName = m_ListCtrl.GetItemText(...);
                              dlg.m_sAge = m_ListCtrl.GetItemText(...);
                              dlg.m_sDOB = m_ListCtrl.GetItemText(...);
                              dlg.DoModal();

                              M Offline
                              M Offline
                              Member_14575556
                              wrote on last edited by
                              #20

                              Thank you.

                              void CMyDlg::ResetListControl() {
                              m_ListControl.DeleteAllItems();
                              int iNbrOfColumns;
                              CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
                              if (pHeader) {
                              iNbrOfColumns = pHeader->GetItemCount();
                              }
                              for (int i = iNbrOfColumns; i >= 0; i--) {
                              m_ListControl.DeleteColumn(i);
                              }
                              }

                              I particularly don't understand this line :

                              CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);

                              Could you please explain this line of code. Thanks :)

                              _ 1 Reply Last reply
                              0
                              • M Member_14575556

                                Thank you.

                                void CMyDlg::ResetListControl() {
                                m_ListControl.DeleteAllItems();
                                int iNbrOfColumns;
                                CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
                                if (pHeader) {
                                iNbrOfColumns = pHeader->GetItemCount();
                                }
                                for (int i = iNbrOfColumns; i >= 0; i--) {
                                m_ListControl.DeleteColumn(i);
                                }
                                }

                                I particularly don't understand this line :

                                CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);

                                Could you please explain this line of code. Thanks :)

                                _ Offline
                                _ Offline
                                _Flaviu
                                wrote on last edited by
                                #21

                                I think that line should be:

                                CHeaderCtrl* pHeader = m_ListControl.GetHeaderCtrl();

                                See here[^]. However, that line retrieve first control item from m_ListCtrl object ... does working that line ? I didn't met such approach ...

                                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