Trouble with getting the correct data after UPDATE
Hello,
I'm using Access DB and what I want to do is the following with an ASP:
1-Display the content of a table named "test" (no problem)
2-Update the record where a certain field "FileDesc" is equal to "A", just make it "X" instead.
3-Re-Display the content of "test".
I want to see, on the same ASP page, the content of the table before and after the update.
I tried to do the Update with a recordset and a command but no way. The update is well performed but what I see on the screen is either 2 times the data before the Update or 2 times the data after the update.
Here is the code and thanks for your replies.
<%
dim Connect, objRS, objRS1, objConn, objRSU, strSQL
Connect= "DSN=TC-Sin-Av-Dap;DRIVER={Microsoft Access Driver (*.mdb)}"
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS1 = Server.CreateObject("ADODB.Recordset")
Set objRSU = Server.CreateObject("ADODB.Recordset")
objRS.Open "test", Connect, adCmdTable
Response.Write "Initial data <br>"
While NOT objRS.EOF
'Display the initial content
Response.Write objRS.Fields("FileID").Value & ", " & objRS.Fields("FileRefTC").Value & ", " & objRS.Fields("FileDesc").Value & "<br>"
objRS.MoveNext
Wend
Response.write "<p></p>"
objRS.Close
set objRS = Nothing
'Now change all FileDesc=A to XX
strSQL = "UPDATE test SET FileDesc = 'XX' WHERE FileDesc = 'A'"
objRSU.Open strSQL, Connect, adCmdText
Response.Write "Updated data <br>"
'Display the content after the changes
objRS1.Open "test", Connect, adCmdTable
While NOT objRS1.EOF
Response.Write objRS1(0) & ", " & objRS1(1) & ", " & objRS1(3) & "<br>"
objRS1.MoveNext
Wend
objRS1.Close
set objRS1 = Nothing
%>
The result page is:
Initial data
1, 030528-1, A
2, 030528-2, A
3, 50103-1, A
4, 50103-1, B
5, 50104-2, B
6, 50104-2, B
7, 50105-1, C
8, 50105-1, C
Updated data
1, 030528-1, A
2, 030528-2, A
3, 50103-1, A
4, 50103-1, B
5, 50104-2, B
6, 50104-2, B
7, 50105-1, C
8, 50105-1, C
The changes are not displayed while in the DB they are done.
Thanks for your help.
|