Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database not updating correctly

Status
Not open for further replies.

mpsoutine

Programmer
Jan 6, 2003
87
US
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
Code:
void CFindDialog::OnButtonEdit() 
{
     //AfxMessageBox("You clicked the Edit Button");

     CTransactionSet TmpSet;
     CListCtrl* pList;
     pList = &m_lcTradeList;
     TmpSet.Open();
     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);
     AfxMessageBox(strIndex);

     if(this->nLcReturnValue == -1)
     {
          AfxMessageBox("You must select and entry");
     }
     else

     {

          CString y;
          y.Format("The unique ID is %d" ,nItemIndex);
          AfxMessageBox(y);

          
          
          
          
          nTransItemData = m_lcTradeList.GetItemData(this->nLcReturnValue);
          CString z;
          z.Format("The TransactionID is %d",nTransItemData);
          AfxMessageBox(z);


          CString sel;
          sel.Format("the TransactionID at Item %d is %d ", nItemIndex, nTransItemData);
          AfxMessageBox(sel);



          

     }
   
     c_DeleteTrade.EnableWindow(false);
     c_EditTrade.EnableWindow(false);

     //TmpEdTrdDlg.SetListCtrl(pList,this->nLcReturnValue);

     
     TmpEdTrdDlg.DoModal(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.

Code:
void CEditTradeDialog::OnEditTrade() 
{

     UpdateData();
     
     CString strText;
     strText.Format("The ID OnEditTrade is: %d", nTradeID);
     AfxMessageBox(strText);

     CTransactionSet TmpTransSet;
     
     if(!TmpTransSet.IsOpen())
          TmpTransSet.Open();

     TmpTransSet.Edit();

     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.Update();

     //TmpTransSet.UpdateItem(this->pList, this->nTradeID);

     

     this->ClearContents();
     CDialog::OnCancel();

}


Below is my code for the DoModal()

Code:
int CEditTradeDialog::DoModal(int ID)
{

     CString strID;
     strID.Format("the ID in DoModal is: %d",ID);
     AfxMessageBox(strID);

     
     CTransactionSet TmpSet;
     if(!TmpSet.IsOpen())
     {
          TmpSet.Open();
     }

     


     this->nTradeID = ID;

     TmpSet.LocateTrade(this->nTradeID);

     //Populate Buyer edit control
     this->m_strBuyer = TmpSet.m_Buyer;

     //Polulate Seller edit control
     this->m_strSeller = TmpSet.m_Seller;

     //Populate BuyerBroker edit control
    int nBuyerBrokerNumber = TmpSet.m_BuyerBrokerNumber;
    CString strBuyerBrokerNumber;
     strBuyerBrokerNumber.Format("%d", nBuyerBrokerNumber);
     //AfxMessageBox(strBuyerBrokerNumber);
    this->m_strBuyerBrokerNumber = strBuyerBrokerNumber;
          
     
     //Populate BuyerBrokerCommission
     double dBuyerBrokerComm = TmpSet.m_BuyerBrokerCommission;
     CString strBuyerBrokerComm;
     strBuyerBrokerComm.Format("%f",dBuyerBrokerComm);
     this->m_strBuyerBrokerComm = strBuyerBrokerComm;

     //Populate SellerBroker edit control
     int nSellerBrokerNumber = TmpSet.m_SellerBrokerNumber;
     CString strSellerBrokerNumber;
     strSellerBrokerNumber.Format("%d",nSellerBrokerNumber);
     this->m_strSellerBrokerNumber = strSellerBrokerNumber;


     //Populate SellerBrokerCommission edit control
     double dSellerBrokerComm = TmpSet.m_SellerBrokerCommision;
     CString strSellerBrokerComm;
     strSellerBrokerComm.Format("%f",dSellerBrokerComm);
     this->m_strSellerBrokerComm = strSellerBrokerComm;
     
     //Populate TradeDate edit control
    this->m_strTradeDate = TmpSet.m_TradeDate;

     //Populate SettlementDate edit control
     this->m_strSettlementDate = TmpSet.m_SettlementDate;

     //Populate MaturityDate edit control
     this->m_strMaturityDate = TmpSet.m_MaturityDate;
     
     //Populate Amount edit control     
     this->m_strAmount = TmpSet.m_Amount;

     //Populate Rate edit control
     double dRate = TmpSet.m_Rate;
     CString strRate;
     strRate.Format("%f",dRate);
     this->m_strRate = strRate;

     //Populate NumberOfDays edit control
     int nNumberOfDays = TmpSet.m_NumberOfDays;
     CString strNmbrDys;
     strNmbrDys.Format("%d",nNumberOfDays);
     this->m_strNumberOfDays = strNmbrDys;
          
     //Populate Collateral Description edit control
     this->m_strSecurityDescription = TmpSet.m_CollateralDescription;




     return CDialog::DoModal();
}


Below is the function for locating a specific record in the database. I'm searching the database using the unique ID for each transaction.

Code:
BOOL CTransactionSet::LocateTrade(int nID)
{


	int nItID = nID;

	CString strText;
	strText.Format("LocateTrade() called.  The ID being searched for is %d", nItID);
	AfxMessageBox(strText);


	if(IsOpen())
	{
		AfxMessageBox("DB is open");
		Close();
	}

	m_strFilter.Format("TransactionID = %d", nID); //This will locate a record with a specific field value
	
	Open();//You must call this member function to run the query defined 
		   //by the recordset. Before calling Open, you must construct the 
	       //recordset object. 



	return (IsEOF()? FALSE:TRUE);

}
 
You may have better luck posting this in a database specific Forum. This is a general database forum

Access VBA Forum705
Access SQL Forum701
SQL Server Forum183

If it's not one of those, try the 'Browse Forums' link.

Leslie
 
It looks like C++, so I'd be (safe) to assume you're running MSVC6?


If you're running into problems dealing with the (MFC?)-provided controls, use the C++ forum. Also, I'd recommend you post less code, or highlight your code with a different color. i.e.

Code:
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
Code:
HIGHLIGHTED_CODE();
Code:
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines



Tedious, I know, but it really helps.
 
What the highlighted stuff looks like with TGML enabled:

Code:
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
Code:
HIGHLIGHTED_CODE();
Code:
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
    //ETC, 50 lines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top