简体   繁体   中英

Compare two primary keys (Access database) with ASP

I have two open queries from one Access 2010 database. I'm using ASP.

I want to simply compare the primary key fields in ASP with an IF… THEN statement. They look the same on screen when I display, but it just throws up an error when I try and compare them.

Can I convert them to a value?

IF rsdata4("ID") = rsdata("ID")
    THEN Response.Write ("XXX")
END IF

Well, if possible, I would suggest that you re-execute the sql used to fill both table objects into ONE single new query. It will run faster, but also tend to be a lot less code. So do a relational “join” between the two tables.

I suppose you can loop over each row in table A, and look for it in table B.

And, there is a filter/select command for a table object, so it would at least eliminate the 2nd loop.

So, you should be able to use this code:

We are going to look for and find “ID” from table A, and find it in table B.

    Dim OneRow As DataRow
    Dim FoundValues() As DataRow
    For Each OneRow In tableA.Rows
        FoundValues = tableB.Select("ID = " & OneRow("ID"))
        If FoundValues.Length > 0 Then
            Debug.Print("Found for ID = " & OneRow("ID"))
            ' found one
        End If
    Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM