Thread: Access database not updating correctly

  1. #1
    Registered User
    Join Date
    Mar 2003

    Access database not updating correctly

    Hi Everyone. I have a dialog box with a list control; populated with the contents of a database, an "Edit Trade" button and "Delete Trade" button. I select a item in the list control and then click "Edit Trade" This generates another dialog box, Edit Trade Dialog with controls populated with the data from the item in the list control. This control also has a "Edit" button. The general idea is that the user can change the data in the edit controls and then click the "Edit" button.

    This is the problem. The data from any of the records I edit gets stored in the first record of the database and the original record I changed remains the same. I can't figure out why this is happening. I've checked the value of the item index from the list control. I selecting the correct item. I'm also using SetItemData() for each item in the list control. This value is being set to the TradeID for each record. This seems to be working fine as well.

    Here is the code from FindDialog to populate the list control
    void CFindDialog::OnButtonEdit() 
         //AfxMessageBox("You clicked the Edit Button");
         CTransactionSet TmpSet;
         CListCtrl* pList;
         pList = &m_lcTradeList;
         CEditTradeDialog TmpEdTrdDlg;
         int nTransItemData;
         //this will give us the item ID
         this->nLcReturnValue = m_lcTradeList.GetNextItem(-1,LVNI_SELECTED);
         int nItemIndex = this->nLcReturnValue;
         CString strIndex;
         strIndex.Format("the index %d", nItemIndex);
         if(this->nLcReturnValue == -1)
              AfxMessageBox("You must select and entry");
              CString y;
              y.Format("The unique ID is %d" ,nItemIndex);
              nTransItemData = m_lcTradeList.GetItemData(this->nLcReturnValue);
              CString z;
              z.Format("The TransactionID is %d",nTransItemData);
              CString sel;
              sel.Format("the TransactionID at Item %d is %d ", nItemIndex, nTransItemData);

    here is the code from EditTradeDialog for the OnEdit() button this function should update the record whose fields populate the edit controls of this dialog box.

    void CEditTradeDialog::OnEditTrade() 
         CString strText;
         strText.Format("The ID OnEditTrade is: %d", nTradeID);
         CTransactionSet TmpTransSet;
         TmpTransSet.m_Buyer = this->m_strBuyer;
         TmpTransSet.m_Seller = this->m_strSeller;
         TmpTransSet.m_BuyerBrokerNumber = atoi(this->m_strBuyerBrokerNumber);
         TmpTransSet.m_BuyerBrokerCommission = atof(this->m_strBuyerBrokerComm);
         TmpTransSet.m_SellerBrokerNumber = atoi(this->m_strSellerBrokerNumber);
         TmpTransSet.m_SellerBrokerCommision = atof(this->m_strBuyerBrokerComm);
         TmpTransSet.m_TradeDate = this->m_strTradeDate;
         TmpTransSet.m_SettlementDate = this->m_strSettlementDate;
         TmpTransSet.m_MaturityDate = this->m_strMaturityDate;
         TmpTransSet.m_Amount = this->m_strAmount;
         TmpTransSet.m_Rate = atof(this->m_strRate);
         TmpTransSet.m_NumberOfDays = atoi(this->m_strNumberOfDays);
         TmpTransSet.m_CollateralDescription = this->m_strSecurityDescription;
         //TmpTransSet.UpdateItem(this->pList, this->nTradeID);

  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer
    I'm not 100% sure (I use CRecordSet) but don't you have to tell the Database that you are changing it with calls to


    I have also had problems because I opened the record set before I told the DB I was going to change it.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  2. CGI with MS Access database integration
    By Tarran in forum Tech Board
    Replies: 12
    Last Post: 01-11-2005, 08:47 AM
  3. connecting to ms access database
    By fkheng in forum Windows Programming
    Replies: 12
    Last Post: 07-06-2003, 07:49 PM
  4. Database Programming In C
    By hanry in forum C Programming
    Replies: 0
    Last Post: 11-27-2001, 07:16 AM
  5. Database Access
    By bubbajones in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2001, 10:05 PM