Problem Comparing Values from two Different CRecordsets

Posted on 2004-04-25
Last Modified: 2013-11-20
I have two tables in Access (and SQL Server - but for this roof of concept, I'm using Access). One table has the fields ipaddress and device name, the other table has locaton information (street, city, state) along with a hostname field that I will use to relate to te previous table via the device name field.

When this utility hits prime time, I will use another search and comparison method (probably), but was trying to whip up a simple proof of concept segment to confirm that I can enter an IP address and return an address. Silly me. I haven't used the CRecordset objects for a while, and am hoping it's something obvious I'm missing.

At any rate, I created a datasource to the database, and then created two CRecordset classes, one to each table. I also created a member variable to each recordset class for easy access. I start by grabbing the IP from the text box, strip off the first three octets, and then check each value in the table that holds the IPs. Initially I started searching for the three octets in a substring, but after that didn't work, I stripped off the first three octets of each value to be tested. Still it doesn't work. I've run it through the debugger, and it appears to function, and I also send each value being tested to a static text box to watch what's going on.

The problem is, it never returns a match, yet if I do a "Find" in Access, or in its previous text version, I find the address. There are over 435,000 records, but I don't think there is a size limit to the recordset because it looks like it cycles through it. So, I wonder why I never find a match.

If anyone has any ideas, I would greatly appreciate them.

void CTboxDlg::OnOK()
      // TODO: Add extra validation here
      CString                  strAddress;
      CString                  addressBuf;
      CString                  strLocation;
      CString                  locBuf;
      CString                  buf;
      CString                  tempBuf;
      char                  lpBuf[MAX_PATH];
      char                  lpTmp[MAX_PATH];
      char                  szbuf[MAX_PATH];
      char                  szbuffer[MAX_PATH];

      GetDlgItemText (IDC_COMPUTERNAME, strAddress);
      lstrcpy (lpTmp, strAddress);
      addressBuf = SplitIP (lpTmp);
      lstrcpy (szbuf, addressBuf);

      //see if addressBuf is a substring in the Router table
      BOOL bFound = FALSE;
      while ((m_tblRouter.IsEOF ()!= TRUE) && (bFound == FALSE))
            buf = m_tblRouter.m_IP;
            tempBuf = SplitIP (lpBuf);
            //if (lpBuf == addressBuf)
            lstrcpy (szbuffer, tempBuf);
            int nComp = lstrcmp (szbuf, szbuffer);
            if (nComp == 0)
                  strLocation = m_tblRouter.m_routerName;
                  AfxMessageBox (strLocation);
                  bFound = TRUE;
                  SetDlgItemText (IDC_STATUS, buf);
      locBuf = m_tblLocation.m_hostname;
      BOOL bDone = FALSE;
      while ((m_tblLocation.IsEOF() != TRUE) && (bDone = TRUE))
            if (locBuf == strLocation)
                  wsprintf (lpBuf, "%s\n", m_tblLocation.m_street);
                  wsprintf (lpBuf, "%s\n", m_tblLocation.m_city);
                  wsprintf (lpBuf, "%s\n", m_tblLocation.m_st);
                  SetDlgItemText (IDC_LOCATION, lpBuf);
                  bDone = TRUE;
                  locBuf = m_tblLocation.m_hostname;

CString CTboxDlg::SplitIP(char *ip_address)
      static char      upper_address[MAX_PATH];
      static char lower_address[MAX_PATH];
      char            *ua = upper_address;
      char            *la = lower_address;
      CString            uAddress("");
      int                  len;
      int                  dotcount;
      LPSTR            lpReturn = NULL;

      FillMemory (upper_address, MAX_PATH, '\0');
      FillMemory (lower_address, MAX_PATH, '\0');

      len = lstrlen (ip_address);
      dotcount = 0;
      for (; *ip_address != '\0'; ip_address++)
            if (*ip_address == '.')
            if (dotcount < 3)
                  *ua++ = *ip_address;
            if (dotcount == 3)
                  *la++ = *ip_address;
      uAddress = upper_address;
      return uAddress;

Question by:jpetter
LVL 44

Accepted Solution

AndyAinscow earned 500 total points
ID: 10915831
I'd put a breakpoint and single step in your loop.  Check the IP address you have in the edit is the one you are comparing for.

A general point why not construct your SQL statement with the comparison built into that.  Do you know how to make an SQL based on two or more tables and with a comparison clause (WHERE) ?

Author Comment

ID: 10931009
I did have a break point set there and didn't notice anything that I didn't anticipate. However, I didn't step through all 400K + records, so I didn't see the comparison I wanted to.

As you suggest, it is a bad design, and a bad idea. I was paged onto a conference bridge Sunday morning and was hit cold with coming up with a proof of concept by noon on Monday. I panicked, and went down what I thought would be a "wham, bam" quick proof of concept, even though it was not based upon a solution we would implement. I did do some searching around on SQL statements, and did the proof that way.

Thanks for your help,

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
How to know only "File created" with EventLog 3 34
Change owner from userA to server Local Administrators 7 62
Window placement 17 82
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question