Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem Comparing Values from two Different CRecordsets

Posted on 2004-04-25
2
Medium Priority
?
187 Views
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.

Thanks,
Jeff
*************************************************
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
      m_tblRouter.MoveFirst();
      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;
            }
            else
            {
                  SetDlgItemText (IDC_STATUS, buf);
                  m_tblRouter.MoveNext();
            }
      }
      
      m_tblLocation.MoveFirst();
      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;
            }
            else
            {
                  m_tblLocation.MoveNext();
                  locBuf = m_tblLocation.m_hostname;
            }
      }
      
      //CDialog::OnOK();
}

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 == '.')
                  dotcount++;
            if (dotcount < 3)
                  *ua++ = *ip_address;
            if (dotcount == 3)
                  *la++ = *ip_address;
      }
      uAddress = upper_address;
      return uAddress;

}
0
Comment
Question by:jpetter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 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) ?
0
 

Author Comment

by:jpetter
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,
Jeff
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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