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. Hi there all again! This time with an improvement! (and more clear question about C++ ADO) :)

Hi there all again! This time with an improvement! (and more clear question about C++ ADO) :)

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++databasehelpannouncement
5 Posts 2 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.
  • S Offline
    S Offline
    symeramon
    wrote on last edited by
    #1

    RecordsetPtr rsUrun;
    rsUrun.CreateInstance(__uuidof(Recordset));
    try{

    _variant_t Holder;

    CString cQry=_T("");
    CString cTmp=_T("");
    _stUrun stTmp;
    vUrun.clear();

    cQry=_T("Select * From urun order by adi");
    //AfxMessageBox(cQry);
    rsUrun->Open(_variant_t(cQry),AdoTest.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
    CStringArray caTmp;
    int nPs=0;
    while(!rsUrun->adoEOF)
    {
    stTmp.cUrunAd=_T("");
    stTmp.dBirimf=0;
    stTmp.nDBID=0;

    Holder = rsUrun->GetCollect("urunid");//id
    if(Holder.vt!=VT\_NULL) stTmp.nDBID=atoi((char\*)\_bstr\_t(Holder));
    
    Holder = rsUrun->GetCollect("adi");//name
    if(Holder.vt!=VT\_NULL) stTmp.cUrunAd=(char\*)\_bstr\_t(Holder);
    
    Holder = rsUrun->GetCollect("birimf");//cost
    if(Holder.vt!=VT\_NULL) stTmp.dBirimf=atof((char\*)\_bstr\_t(Holder));
    
    vUrun.push\_back(stTmp);
    CString adi = rsUrun->GetCollect("adi");
    listbo1.AddString(\_T(adi));
    int gfujf = listbo1.GetItemData(listbo1.GetCount()-1);
    

    rsUrun->MoveNext();

    SO here is the code, could you please help me on how can I get the listbox item's id in order to use it in an update query?? Here is my button below, I did some work on it but seems no good :(

    void CTestADSSQLDlg::OnBnClickedButton1()
    {
    _RecordsetPtr rsUrun;
    rsUrun.CreateInstance(__uuidof(Recordset));
    CString cQry=_T("Update urun set adi='%s' where urunid='%d'", editbo1;

    rsUrun->Open(_variant_t(cQry),AdoTest.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
    }

    D 1 Reply Last reply
    0
    • S symeramon

      RecordsetPtr rsUrun;
      rsUrun.CreateInstance(__uuidof(Recordset));
      try{

      _variant_t Holder;

      CString cQry=_T("");
      CString cTmp=_T("");
      _stUrun stTmp;
      vUrun.clear();

      cQry=_T("Select * From urun order by adi");
      //AfxMessageBox(cQry);
      rsUrun->Open(_variant_t(cQry),AdoTest.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
      CStringArray caTmp;
      int nPs=0;
      while(!rsUrun->adoEOF)
      {
      stTmp.cUrunAd=_T("");
      stTmp.dBirimf=0;
      stTmp.nDBID=0;

      Holder = rsUrun->GetCollect("urunid");//id
      if(Holder.vt!=VT\_NULL) stTmp.nDBID=atoi((char\*)\_bstr\_t(Holder));
      
      Holder = rsUrun->GetCollect("adi");//name
      if(Holder.vt!=VT\_NULL) stTmp.cUrunAd=(char\*)\_bstr\_t(Holder);
      
      Holder = rsUrun->GetCollect("birimf");//cost
      if(Holder.vt!=VT\_NULL) stTmp.dBirimf=atof((char\*)\_bstr\_t(Holder));
      
      vUrun.push\_back(stTmp);
      CString adi = rsUrun->GetCollect("adi");
      listbo1.AddString(\_T(adi));
      int gfujf = listbo1.GetItemData(listbo1.GetCount()-1);
      

      rsUrun->MoveNext();

      SO here is the code, could you please help me on how can I get the listbox item's id in order to use it in an update query?? Here is my button below, I did some work on it but seems no good :(

      void CTestADSSQLDlg::OnBnClickedButton1()
      {
      _RecordsetPtr rsUrun;
      rsUrun.CreateInstance(__uuidof(Recordset));
      CString cQry=_T("Update urun set adi='%s' where urunid='%d'", editbo1;

      rsUrun->Open(_variant_t(cQry),AdoTest.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
      }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      symeramon wrote:

      CString cQry=_T("Update urun set adi='%s' where urunid='%d'", editbo1;

      Seems a parenthesis has gone AWOL.

      symeramon wrote:

      SO here is the code, could you please help me on how can I get the listbox item's id...

      Umm, since you are using MFC, why not just assign it a CListBox member variable? Use ClassWizard (or equivalent).

      "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

      "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

      S 1 Reply Last reply
      0
      • D David Crow

        symeramon wrote:

        CString cQry=_T("Update urun set adi='%s' where urunid='%d'", editbo1;

        Seems a parenthesis has gone AWOL.

        symeramon wrote:

        SO here is the code, could you please help me on how can I get the listbox item's id...

        Umm, since you are using MFC, why not just assign it a CListBox member variable? Use ClassWizard (or equivalent).

        "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

        "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

        S Offline
        S Offline
        symeramon
        wrote on last edited by
        #3

        Thanks David, at least you answered my question... But the main problem is how can I get the id from vector to use it in the button click event?

        D 1 Reply Last reply
        0
        • S symeramon

          Thanks David, at least you answered my question... But the main problem is how can I get the id from vector to use it in the button click event?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          symeramon wrote:

          But the main problem is how can I get the id from vector...

          What does a vector have to do with any of this?

          symeramon wrote:

          ...use it in the button click event?

          BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
          //{{AFX_MSG_MAP(CMyDialog)
          ON_BN_CLICKED(IDC_SOME_BUTTON, OnButtonClicked)
          END_MESSAGE_MAP()
          ...
          void CMyDialog::OnButtonClicked()
          {
          m_listbox.AddString(_T("Hello World!"));
          }

          "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

          "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

          S 1 Reply Last reply
          0
          • D David Crow

            symeramon wrote:

            But the main problem is how can I get the id from vector...

            What does a vector have to do with any of this?

            symeramon wrote:

            ...use it in the button click event?

            BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
            //{{AFX_MSG_MAP(CMyDialog)
            ON_BN_CLICKED(IDC_SOME_BUTTON, OnButtonClicked)
            END_MESSAGE_MAP()
            ...
            void CMyDialog::OnButtonClicked()
            {
            m_listbox.AddString(_T("Hello World!"));
            }

            "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

            "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

            S Offline
            S Offline
            symeramon
            wrote on last edited by
            #5

            Thanks for your reply David... Finally I got it, by SetItemData! :)

            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