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. Using MySQl with VC++

Using MySQl with VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++mysqlhelptutorialquestion
6 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.
  • T Offline
    T Offline
    tony_Udz
    wrote on last edited by
    #1

    Hi, I intend to make a sample application in VC++ to using MySQL databases. Can anybody suggest me where and how to start? I am new to databases any help would be great. Thanks in Advance!! Regards, Tony

    R N S 3 Replies Last reply
    0
    • T tony_Udz

      Hi, I intend to make a sample application in VC++ to using MySQL databases. Can anybody suggest me where and how to start? I am new to databases any help would be great. Thanks in Advance!! Regards, Tony

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      Visit this page http://www.codeproject.com/KB/database/[^] and set the language filter to C++ and skill to Beginner. There are plenty of articles that may give you a lead to begin with. Note that there would be nothing specific to MySQL, but they will all speak about databases in general.

      Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

      1 Reply Last reply
      0
      • T tony_Udz

        Hi, I intend to make a sample application in VC++ to using MySQL databases. Can anybody suggest me where and how to start? I am new to databases any help would be great. Thanks in Advance!! Regards, Tony

        N Offline
        N Offline
        nguyenbinh07
        wrote on last edited by
        #3

        It yours: http://files.myopera.com/nguyenbinh07/files/MySQL.rar[^] Have funs!!!

        1 Reply Last reply
        0
        • T tony_Udz

          Hi, I intend to make a sample application in VC++ to using MySQL databases. Can anybody suggest me where and how to start? I am new to databases any help would be great. Thanks in Advance!! Regards, Tony

          S Offline
          S Offline
          Sandeep Saini SRE
          wrote on last edited by
          #4

          Simple 7 Steps :-D

          1)First of all import msado15.dll into your workspace

          #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
          no_namespace rename("EOF", "EndOfFile")

          2)Initialize COM libraries using

          CoInitialize(NULL);

          1. Create connection & record set pointers

          _ConnectionPtr pConn("ADODB.Connection");

          _RecordsetPtr pRst("ADODB.Recordset");

          1. Open data base

          #define STR_DATABASE L"DRIVER={sql server};SERVER=serverName;Database=datbaseName;" L"UID=sa; PWD=sa;"

          HRESULT hr = S_OK;

          hr = pConn->Open(STR_DATABASE, L"", L"", adOpenUnspecified);

          if(FAILED(hr))
          {
          AfxMessageBox ("Error instantiating Connection object\n");
          }

          5)Execute Query and read values

          try
          {
          CString strSQL(“Select * From MyTable”);
          pRst->Open( _variant_t(strSQL),_variant_t((IDispatch *) pConn, true),adOpenDynamic, adLockReadOnly,adCmdText);

          if(!pRst->EndOfFile){
          CString strValue = (char*)(_bstr_t)pRst->Fields->Item[“FieldName”]- >Value;

          int nValue = (long)pRst->Fields->Item[“FieldName”]->Value;

          // Here “FieldName” is the column name of table. You will get the value of this column in the corresponding variable.

          }

          catch(_com_error &ce)
          {
          AfxMessageBox(ce.ErrorInfo);
          OR
          AfxMessageBox(ce.Description());

          }

          6)Close connection and record set pointers

          if(pRst->State == adStateOpen)
          pRst->Close();
          if(pConn->State == adStateOpen)
          pConn->Close();

          7)UnInitialized COM library

          ::CoUninitialize();

          T 1 Reply Last reply
          0
          • S Sandeep Saini SRE

            Simple 7 Steps :-D

            1)First of all import msado15.dll into your workspace

            #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
            no_namespace rename("EOF", "EndOfFile")

            2)Initialize COM libraries using

            CoInitialize(NULL);

            1. Create connection & record set pointers

            _ConnectionPtr pConn("ADODB.Connection");

            _RecordsetPtr pRst("ADODB.Recordset");

            1. Open data base

            #define STR_DATABASE L"DRIVER={sql server};SERVER=serverName;Database=datbaseName;" L"UID=sa; PWD=sa;"

            HRESULT hr = S_OK;

            hr = pConn->Open(STR_DATABASE, L"", L"", adOpenUnspecified);

            if(FAILED(hr))
            {
            AfxMessageBox ("Error instantiating Connection object\n");
            }

            5)Execute Query and read values

            try
            {
            CString strSQL(“Select * From MyTable”);
            pRst->Open( _variant_t(strSQL),_variant_t((IDispatch *) pConn, true),adOpenDynamic, adLockReadOnly,adCmdText);

            if(!pRst->EndOfFile){
            CString strValue = (char*)(_bstr_t)pRst->Fields->Item[“FieldName”]- >Value;

            int nValue = (long)pRst->Fields->Item[“FieldName”]->Value;

            // Here “FieldName” is the column name of table. You will get the value of this column in the corresponding variable.

            }

            catch(_com_error &ce)
            {
            AfxMessageBox(ce.ErrorInfo);
            OR
            AfxMessageBox(ce.Description());

            }

            6)Close connection and record set pointers

            if(pRst->State == adStateOpen)
            pRst->Close();
            if(pConn->State == adStateOpen)
            pConn->Close();

            7)UnInitialized COM library

            ::CoUninitialize();

            T Offline
            T Offline
            tony_Udz
            wrote on last edited by
            #5

            Can i go like this as well ========================================================================================= try { CDaoDatabase* pCDaoDb = NULL; CDaoRecordset* pPointsSet = NULL; pCDaoDb = new CDaoDatabase(); pCDaoDb->Open("C:\\temp\\sample2.mdb", FALSE, FALSE, ""); pPointsSet = new CDaoRecordset(pCDaoDb); if (!pPointsSet->IsOpen()) { pPointsSet->Open(dbOpenTable, "STUDENT", 0); } COleVariant oleVariant; oleVariant = pPointsSet->GetFieldValue("STUDENTID"); long lTemp = oleVariant.lVal; oleVariant = pPointsSet->GetFieldValue("Address"); CString strTemp = oleVariant.pcVal; CString strTemp2 = strTemp.AllocSysString(); int nCount = pPointsSet->GetRecordCount(); //pPointsSet-> } catch(CDaoException* e) { //int nError = e->ReportError(); CString error = e->m_pErrorInfo->m_strDescription; MessageBox( NULL, error, "ERROR", MB_OK ); } =========================================================================================

            S 1 Reply Last reply
            0
            • T tony_Udz

              Can i go like this as well ========================================================================================= try { CDaoDatabase* pCDaoDb = NULL; CDaoRecordset* pPointsSet = NULL; pCDaoDb = new CDaoDatabase(); pCDaoDb->Open("C:\\temp\\sample2.mdb", FALSE, FALSE, ""); pPointsSet = new CDaoRecordset(pCDaoDb); if (!pPointsSet->IsOpen()) { pPointsSet->Open(dbOpenTable, "STUDENT", 0); } COleVariant oleVariant; oleVariant = pPointsSet->GetFieldValue("STUDENTID"); long lTemp = oleVariant.lVal; oleVariant = pPointsSet->GetFieldValue("Address"); CString strTemp = oleVariant.pcVal; CString strTemp2 = strTemp.AllocSysString(); int nCount = pPointsSet->GetRecordCount(); //pPointsSet-> } catch(CDaoException* e) { //int nError = e->ReportError(); CString error = e->m_pErrorInfo->m_strDescription; MessageBox( NULL, error, "ERROR", MB_OK ); } =========================================================================================

              S Offline
              S Offline
              Sandeep Saini SRE
              wrote on last edited by
              #6

              Ya definitely!

              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