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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem of redundant records

Status
Not open for further replies.

Larree

Programmer
Dec 31, 2002
20
SG
Hi all,
I am facing a problem for my program. Basically I intend to update my database each time an event occurs. However I want to eliminate redundant records as in if a particular identity is already in my record for today, it must not appear again. Ut is ok if it appears tomorrow since the date will be changed by then. However my following code generates error. Not sure if my filter string is the one at fault or the GetRecordCount() function to detect the presence of the ID for that day is errorneous. Here is teh code:

m_pCapturedResults->m_strFilter = "Date = '" + changedate + "' AND Serial Number = '" + sSnr +"'";


if(m_pCapturedResults->GetRecordCount() == 0)
{
AfxMessageBox("Start Time Recorded", MB_ICONINFORMATION);

m_pCapturedResults->m_Protocol_Type = sTagType;
m_pCapturedResults->m_Time_Started = changetime;

m_pCapturedResults->m_Date = changedate;
m_pCapturedResults->m_Serial_Number = sSnr;

m_pCapturedResults->Update(); // Update Database
}

if(m_pCapturedResults->GetRecordCount() == 1)
{
AfxMessageBox("End Time Recorded.", MB_ICONINFORMATION);

m_pCapturedResults->m_Time = changetime;
m_pCapturedResults->Update(); // Update Database
}

If the recordcount is 1, the record is supposed to find the entry wif the same sSnr and update the columns. But it seems like my code does not eliminate the redundancy problem and it seems that it may not even have entered either of the if loop even though I do not have any records which meet the filter. Please advice......Thanks
 
>>Please advice
The first thing to do is fix your database by adding a unique constraint based on the two columns. That way the database does all the heavy lifting, as it should, and all you do is receive an error when you try to insert the new record. The error message and number will denote the failure was due to the constraint.

Obviously once you fix your database you will have no need for the code that is giving you the problem.

In the future when you post includes a statement such as “However my following code generates error” you need to include the error information and define “which line” in your code produces the error.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top