Problem Comparing Values from two Different CRecordsets

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;

Who is Participating?
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
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) ?
jpetterAuthor Commented:
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,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.