简体   繁体   English

用 ASP 比较两个主键(Access 数据库)

[英]Compare two primary keys (Access database) with ASP

I have two open queries from one Access 2010 database.我有来自一个 Access 2010 数据库的两个打开的查询。 I'm using ASP.我正在使用 ASP。

I want to simply compare the primary key fields in ASP with an IF… THEN statement.我想简单地将 ASP 中的主键字段与IF… THEN语句进行比较。 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.好吧,如果可能的话,我建议您重新执行 sql 用于将两个表对象填充到一个新查询中。 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.我想您可以遍历表 A 中的每一行,然后在表 B 中查找它。

And, there is a filter/select command for a table object, so it would at least eliminate the 2nd loop.而且,表 object 有一个过滤/选择命令,因此它至少会消除第二个循环。

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.我们将从表 A 中查找并找到“ID”,然后在表 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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