ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 30th, 2003, 05:50 PM
Chris Hall001 Chris Hall001 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: oxford (uk)
Posts: 9 Chris Hall001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Terminal Update problems.....

The following code steadfastly refuses to UPDATE:
<%ENABLESESSIONSTATE=False %>
<%



'Connect To Database
Dim DB
Set DB = Server.CreateObject ("ADODB.Connection")
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\test\test2.2.mdb")
sid = Request.Form("SprogNo")
'Dim rs
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open "SELECT * FROM SprogTbl", DB
rs.movefirst
do until rs.EOF
for each sid in rs.fields
sql="UPDATE SprogTbl SET "
sql=sql & "Report='" & Request.Form("Report" & sid) & "',"
sql=sql & "rep2='" & Request.Form("rep2" & sid) & "',"
sql=sql & " WHERE SprogNo='" & sid & "',"

on error resume next
DB.execute sql
RS.movenext
next
loop
rs.movefirst
set rs= nothing
set DB = nothing

%>


The info successfully sent by the form is:

POST Data:
SprogNo1=1&Report1=g&rep21=g&SprogNo2=2&Report2=b&rep22=b&SprogNo3=3&Report3=u&rep23=u

I need to be able to UPDATE multiple, non sequential records in MS access. So far the above code has no effect whatsoever.

any heklp gratefully recieved....

Chris Hall

Reply With Quote
  #2  
Old July 31st, 2003, 07:27 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 6 m 22 sec
Reputation Power: 76
Code:
DB.execute  ( sql ) 

Also, in this line - Request.Form("Report" & sid) , I'm not sure why you have the &sid inside the parentheses.
Finally, I don't think this is causing the problem, but typically you would do
Code:
 rs.close
DB.close
set rs= nothing 
set DB = nothing 

To aid in your trouble shooting, you could try adding some code to display the results of the SELECT * query, to be sure you're getting the data in the first place.
HTH
Dave
__________________
--Dave--

U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM=

Reply With Quote
  #3  
Old July 31st, 2003, 12:07 PM
Chris Hall001 Chris Hall001 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: oxford (uk)
Posts: 9 Chris Hall001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Troblesome UPDATE

Dave,

Thx. I modified the code to

DB.execute (sql)

the update still refuses to work. thx 4 the close code, as I'm a total beginer at this I don't have a clue how to make the query display the results.

Any further ideas/ help greatly appreciated.

Chris

Reply With Quote
  #4  
Old August 4th, 2003, 08:13 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 6 m 22 sec
Reputation Power: 76
Hm. Try this. I'm just guessing though
Code:
sql="UPDATE SprogTbl SET " 
sql=sql & "Report='" & Request.Form("Report") & "'," 
sql=sql & "rep2='" & Request.Form("rep2") & 
sql=sql & " WHERE SprogNo='" & sid & 

Reply With Quote
  #5  
Old August 5th, 2003, 08:01 PM
Chris Hall001 Chris Hall001 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: oxford (uk)
Posts: 9 Chris Hall001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
nightmare on multiple and non-sequential update street

Thank for your time. Still no luck. Concise statement of the problem is below. All and any help greatly appreciated.


Using the old for x = 1 to 3 front- end which posts the correct data (see below). It doesn’t UPDATE. Neither of the WHERE statements work.


Code is:

Dim DB
Set DB = Server.CreateObject ("ADODB.Connection")
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\test\test2.2.mdb")
dim sid
sid = Request.Form("SprogNo")
Dim rs
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open "SELECT * FROM SprogTbl", DB
rs.movefirst
do until rs.EOF=TRUE
for each sid in rs.Fields
sql="UPDATE SprogTbl SET "
sql=sql & "Report='" & Request.Form("Report") & "',"
sql=sql & "rep2='" & Request.Form("rep2") & "',"
'sql=sql & " WHERE SprogNo='" & sid & "',"
sql=sql & " WHERE SprogNo='" & Request.Form("SprogNo") & "',"

on error resume next
DB.execute (sql)
RS.movenext
next
loop

==========================================
Interestingly, nothing’s happening here either UPDATE format (report amend 2.42) Additionally, the last UPDATE option would have been better as it didn’t invoke sid. All interchanges of sid with ‘”SprogNo”’ in all combinations tried.- and do not update:

==========================================

rs.Open "SELECT * FROM SprogTbl", DB
rs.movefirst
for each sid in rs.fields
rs.Fields("SprogNo") = Request.Form("SprogNo" & sid)
rs.Fields("Report") = Request.Form("Report" & sid)
rs.Fields("rep2") = Request.Form("rep2" & sid)
rs.update
next
'wend
'Dim strSQL
' strSQL = "UPDATE SprogTbl SET Report = '" & Report & _
' "', rep2 = '" & rep2 & _
' "' WHERE ((SprogTbl.SprogNo)='" & SprogNo & "');"
'DB.execute(strSQL)


RS.movenext
'Next

==============================================

• POST Data:
SprogNo1=1&Report1=a&rep21=d&SprogNo2=2&Report2=b&rep22=e&SprogNo3=3&Report3=c&rep23=f&SprogNo4=&Report4=&rep24=

Reply With Quote
  #6  
Old August 6th, 2003, 09:28 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 6 m 22 sec
Reputation Power: 76
Well, I'm not sure I quite get the setup of your db, but have you tried updating with the recordset instead of using sql?
Code:
Dim DB, sid, rs
sid = Request.Form("SprogNo")

'make connection to DB
Set DB = Server.CreateObject ("ADODB.Connection") 
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\test\test2.2.mdb") 

'make recordset and open
Set rs = Server.CreateObject ("ADODB.Recordset") 
rs.open "SprogTbl", DB

'Do the update with asp
If rs("SprogNo") = request("SprogNo") Then
   rs("Report") = Request("Report")
   rs("Rep2") = Request("Rep2")
End If
rs.close
set rs = nothing
DB.close 
set DB = nothing 
This is untested code, you might need to add logic to make it loop through the database, or other modifications, but I think it should work, since you're only updating the 2 fields with form values. Just an idea.
HTH
Dave

Reply With Quote
  #7  
Old August 6th, 2003, 05:25 PM
Chris Hall001 Chris Hall001 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: oxford (uk)
Posts: 9 Chris Hall001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The Database is a prototype assessment tracking system. I am a school teacher. "Sprog" is uk slang for a kid. hence SprogNo. All the report data is displayed in inout boxes so that colleagues can continually update their assessment data. The table is as follows:

SprogTbl
SprogNo, Report, rep2, UPN,
1, a,d,
2 ,b, e,
3, c, f,
4 ,


I tried the rs update . It still didn't do the update. I was wondering does it need some kind of loop for each record to be updated? If so, do you have any ideas how this might be done?

I also tried:

If rs.fields("SprogNo") = request.form ("SprogNo" & sid)

no joy. Again - any and all thoughts appreciated.

Regards,

Chris Hall

Reply With Quote
  #8  
Old August 6th, 2003, 06:01 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,717 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 40 m 34 sec
Reputation Power: 688
You might try using a 2nd connection object to execute your sql. I have never tried executing sql on the same connection that holds an open recordset, perhaps there is some conflict.

Reply With Quote
  #9  
Old August 6th, 2003, 07:01 PM
Chris Hall001 Chris Hall001 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: oxford (uk)
Posts: 9 Chris Hall001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
completely baffled

Doug, I really do appreciate the time you have spent on this but I have absolutely no idea how to do what you suggest.

Reply With Quote
  #10  
Old August 6th, 2003, 10:52 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,717 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 40 m 34 sec
Reputation Power: 688
Something like this:

Code:
 
Dim DB 
Dim Con2

Set DB = Server.CreateObject ("ADODB.Connection") 
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\test\test2.2.mdb") 

Set Con2 = Server.CreateObject ("ADODB.Connection") 
Con2.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\test\test2.2.mdb") 


dim sid 
sid = Request.Form("SprogNo") 
Dim rs 
Set rs = Server.CreateObject ("ADODB.Recordset") 
rs.Open "SELECT * FROM SprogTbl", DB 
rs.movefirst 
do until rs.EOF=TRUE 
for each sid in rs.Fields 
sql="UPDATE SprogTbl SET " 
sql=sql & "Report='" & Request.Form("Report") & "'," 
sql=sql & "rep2='" & Request.Form("rep2") & "'," 
'sql=sql & " WHERE SprogNo='" & sid & "'," 
sql=sql & " WHERE SprogNo='" & Request.Form("SprogNo") & "'," 

on error resume next 
Con2.execute (sql) 

RS.movenext 
next 
loop 
__________________
======
Doug G
======
"Hide, hide witch! The good folk come to burn thee. Their keen enjoyment hid behind their gothic mask of duty." -Mark Clifton

Reply With Quote
  #11  
Old August 7th, 2003, 05:16 PM
Chris Hall001 Chris Hall001 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: oxford (uk)
Posts: 9 Chris Hall001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thx Doug

If I set up the two connections as you suggest I get the "file already in use" error for the second connection line. I think the problem is the sid variable (it reads and then posts the first value from the first row of the first field. It then reads the second rows value of the second field, and then the third row value of the third field, etc.).


code below:

<html>
<body>
<%ENABLESESSIONSTATE=False %>
<%

Dim DB
Set DB = Server.CreateObject ("ADODB.Connection")
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\test\test2.2.mdb")
Dim RS
'
Set RS = Server.CreateObject ("ADODB.Recordset")
RS.Open "SELECT * FROM SprogTbl", DB




%>
<form action="report-ammend2.42.asp" method="post"name="form">
<table border=1>
<tr><td>Sprog No.</td>
<td>1st report</td>
<td> 2nd report</td></tr>
<%

dim sid
Response.Write RS.Fields("SprogNo") = sid
rs.movefirst

do until rs.EOF=true

for each sid in RS.Fields
'x = sid + 0

%>
<tr><td><input type="hidden" name="SprogNo<% = sid %>" value="<%Response.Write RS.Fields("SprogNo")%>"><% response.write RS.Fields("SprogNo")%></td>
<td><input type="text" name="Report<%= sid %>" value="<%Response.Write RS.Fields("Report")%>"></td>
<td><input type="text" name="rep2<%= sid %>" value="<%Response.Write RS.Fields("rep2")%>"></td></tr>

<%

rs.movenext
'RS.movefirst

'exit for
'exit do
next
loop
'wend
'exit for
%>
</table>
<br>
<input type="submit" value="submit">
<input type="button" value="Cancel" >

</form>

</body>
</html>

Reply With Quote
  #12  
Old August 8th, 2003, 01:33 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,717 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 40 m 34 sec
Reputation Power: 688
It was just a guess, sorry it didn't work.

I'm still not sure if the conflict is with the connection being open, and I don't recall where the default cursor location is for a recordset if you don't specify it.

Maybe try modifying your recordset open code like
Code:
Set RS = Server.CreateObject ("ADODB.Recordset") 
RS.CursorLocation = adUseClient
RS.LockType = adLockOptimistic
RS.Open "SELECT * FROM SprogTbl", DB 

Reply With Quote
  #13  
Old August 8th, 2003, 02:48 AM
Chris Hall001 Chris Hall001 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: oxford (uk)
Posts: 9 Chris Hall001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
any all ideas greatly appreciated.....

Thx Doug. Tried that and got the following error message:

ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/test/report-ammend2.45.asp, line 25

Line 25 being the line:-

RS.CursorLocation = adUseClient

pls could I run a thought by you? In my first working (but useless model), a value of x is appended to the end of the input box name="". If I try to append the number value from the SprogNo field instaed using sid as a variable the POST data is wrong, and what is appended to the end of the names is the first value from the the first field, the next set of names has the whatever is in the second row of the second field. The third set then has the whatever is in the third row of the third field. For whatever reason the sid variable is picking up data from one row after another, but it's moving across a column (i.e. field) each time.

Incorrect Post data:

SprogNo1=1&Report1=a&rep21=d&SprogNob=2&Reportb=b&rep2b=e&SprogNof=3&Reportf=c&rep2f=f&SprogNo=4&Report=&rep2=

Correct (required) POST data:

SprogNo1=1&Report1=a&rep21=d&SprogNo2=2&Report2=b&rep22=e&SprogNo3=3&Report3=c&rep23=f&SprogNo4=&Report4=&rep24=

Table:

SprogTbl
SprogNo Report rep2
1 a d
2 b e
3 c f
4

strangely, if I reduce the number of records to one I get:

Error Type:
ADODB.Field (0x80020009)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/test/report2.2.asp



code below:

<html>
<body>
<%ENABLESESSIONSTATE=False %>
<%

Dim DB
Set DB = Server.CreateObject ("ADODB.Connection")
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\test\test2.2.mdb")
Dim RS
'
Set RS = Server.CreateObject ("ADODB.Recordset")
RS.Open "SELECT * FROM SprogTbl", DB




%>
<form action="report-ammend2.42.asp" method="post"name="form">
<table border=1>
<tr><td>Sprog No.</td>
<td>1st report</td>
<td> 2nd report</td></tr>
<%

dim sid
Response.Write RS.Fields("SprogNo") = sid
rs.movefirst

do until rs.EOF=true

for each sid in RS.Fields


%>
<tr><td><input type="hidden" name="SprogNo<% = sid %>" value="<%Response.Write RS.Fields("SprogNo")%>"><% response.write RS.Fields("SprogNo")%></td>
<td><input type="text" name="Report<%= sid %>" value="<%Response.Write RS.Fields("Report")%>"></td>
<td><input type="text" name="rep2<%= sid %>" value="<%Response.Write RS.Fields("rep2")%>"></td></tr>

<%

rs.movenext
'RS.movefirst

'exit for
'exit do
next
loop
'wend
'exit for
%>
</table>
<br>
<input type="submit" value="submit">
<input type="button" value="Cancel" >
<br/>
<br/>
</form>

</body>
</html>

Reply With Quote
  #