0

我的代码如下,在复制代码之前我写了问题,当我查询时,它在代码提及中显示 pincode 作为查询,有时显示未找到,现在它显示空白没有结果,即使查询没有错误,我认为问题是当我查询数据时,指针位于上次查询的记录位置,但不再刷新内存并转到数据库或程序的启动,任何人都可以帮助我摆脱

代码在 asp 中查询 mS 访问 mdb 2003

<html>
<body>
<div id ="pin">
<%

  city= Request.Form("username")
  area = Request.Form("password")

    Dim Conn,rs,strSQL

    Set Conn = Server.CreateObject("ADODB.Connection")
     Conn.Open"Provider= Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/pinner/db/database1.mdb") 
    'Conn.Open"DRIVER=Microsoft Access Driver(*.mdb);DBQ=" & Server.MapPath("/pinner/db/Database1.mdb")
    'strSQL = "SELECT pincodes.officename FROM pincodes where pincode = '" & city & "';"
    Set rs = Server.CreateObject("ADODB.Recordset")

    strSQL = "Select  pincode from pincodes  WHERE Districtname = '" & city & "' AND officename = '" & area & "';"
    'strSQL = "Select  pincode from pincodes  WHERE (Districtname  like "&city& *" AND officename like "&area&*");"
    rs.Open strSQL,Conn

    If rs.EOF or rs.BOF Then
    Response.Write ("<br>")
    Response.Write ("[pincode] not found")
    Response.Write ("<br>")
    Else
    Response.Write ("<br>")
    Response.Write (rs("pincode"))
    Response.Write ("<br>")
    End If




rs.close
Conn.close
 Set rs = Nothing
 Set Conn = Nothing

%>
</div>
</body>
</html>
4

1 回答 1

0

要将记录集指针移动到第一条记录:

rs.MoveFirst

要检查记录集中是否有任何记录,您需要检查 EOF 和 BOF 是否都为真:

If (rs.EOF AND rs.BOF) Then
    Response.Write ("<br>")
    Response.Write ("[pincode] not found")
    Response.Write ("<br>")
Else
    Response.Write ("<br>")
    Response.Write (rs("pincode"))
    Response.Write ("<br>")
End If

在我看来,您的查询中可能仍然存在问题,导致您无法找到所需的记录。

于 2013-09-14T19:58:58.523 回答