访问数据连接问题

时间:2015-12-05 10:56:55

标签: ms-access asp-classic insert record

我想在数据库Project.mdb中成功地在一个表中插入记录,但在更新记录时它会显示" No Record Found"。 Access中的表包含以下字段PNR - FNAME - LNAME - SOURCE - DEST - DOJ - NOP 下面的代码没有显示任何错误,但它直接跳转到最后一个语句而不更新或检查值。请帮助。

<%
Dim objConn
Dim objRS
Dim pnrNo
Dim varpnr
Dim varfname
Dim varlname
Dim vardoj
Dim varnop
Dim varsrc
Dim vardest
pnrNO = Request.Form("PNR")
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="& _
            "D:\Project.mdb"
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open "Book", objConn
Dim flag
flag = 0
Do Until objRS.EOF
If objRS("PNR") = pnrNO Then
varpnr = objRS("PNR")
varfname = objRS("FNAME")
varlname = objRS("LNAME")
vardoj = objRS("DOJ")
varnop = objRS("NOP")
varsrc = objRS("SOURCE")
vardest = objRS("DESTINATION")
flag = 1
End if
objRS.MoveNext
Loop
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
%>
<% If flag = 1 Then %>
<html>
<body text="#FFFF00" bgcolor="#000000">

<p align="center"><font face="Cooper Black" size="6">MANAGE 

BOOKING</font></p>
<p align="center">&nbsp;</p>
    <CENTER>
    <form method="POST" action = "Update_Entry.asp">
        <table border="0" width="38%">
        <tr>
            <td width="202">PNR NUMBER</td>
            <td><input type="hidden" name="PNR" 

size="20" value = "<% =varpnr %>"></td>
        </tr>
        <tr>
            <td width="202">FIRST NAME</td>
            <td><input type="text" name="FNAME" 

size="20" value = "<% =varfname %>"></td>
        </tr>
        <tr>
            <td width="202">LAST NAME</td>
            <td><input type="text" name="LNAME" 

size="20" value = "<% =varlname %>"></td>
        </tr>
        <tr>
            <td width="202">DATE OF JOURNEY</td>
            <td><input type="text" name="DOJ" size="20" 

value = "<% =vardoj %>"></td>
        </tr>
        <tr>
            <td width="202">TOTAL PASSENGERS</td>
            <td><input type="text" name="NOP" size="20" 

value = "<% =varnop %>"></td>
        </tr>
        <tr>
            <td width="202">SOURCE</td>
            <td><input type="text" name="SOURCE" 

size="20" value = "<% =varsrc %>"></td>
        </tr>
<tr>
            <td width="202">DESTINATION</td>
            <td><input type="text" name="DESTINATION" 

size="20" value = "<% =vardest %>"></td>
        </tr>
    </table>
        <p><input type="submit" value="UPDATE DETAILS"> 

</p>
        <p>&nbsp;<input type="reset" value="CLEAR"></p>
    </form>
    <p>&nbsp;</p>

</body>

</html>
<% 
else 
response.write("Record Not Found!!")
end if %>

1 个答案:

答案 0 :(得分:0)

您所拥有的代码不会更新记录,只是尝试阅读它们。但是,您将始终拥有一个空记录集,因为读取书表内容的SQL语句不是有效的。这需要遵循:

objRS.Open&#34; select * from Book&#34;,objConn