Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

for x = 1 to 10 (or) for x = 1 to 1000 (Works in one page, not in the other?)

OK.
To the point. This is an Update page, but is going wrong.
On a test script the (Below code view source)
1st Code below, works .(I can either Update the 5 current records (or) 10
It will not give me an error, it will work without a problem)

2nd Code below. Does not work.
If I send it 10, then it will work great.
If I send it 5, then I get
============
Microsoft JET Database Engine error '80040e14' Syntax error in UPDATE statement.
============

So, in the 2nd code, it has to be the actual # or it will not work.

Could someone shed some light on me to why this is happening?
Thank You
Carrzkiss

This one will work without any issues.
====================================
<%@ Language = "VBScript"%>
<%
 
'Declare all local variables
 
dim conn
dim rs
dim strconn
dim strsql
 
strsql = ""
 
'set connection string to local variable
'Dim conn, ConnectString
'ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("dbreg.mdb") & ";Persist Security Info=False"
'Set conn = Server.CreateObject("ADODB.Connection")
'conn.open ConnectString
 
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("db1.mdb") & ";Persist Security Info=False"
set conn = server.createobject("adodb.connection")
conn.open strconn
'Use the execute method of the connection object the insert the record
'build the sql statement based on the input from the form
 
For x = 1 to 10
strSQL = "UPDATE tblUpdateSQL " & _
"SET tblUpdateSQL.FirstName = '" & request("FirstName" & x) & "', " & _
"tblUpdateSQL.lastName = '" & request("LastName" & x) & "' " & _
"WHERE (((tblUpdateSQL.id)=" & x & "))"
response.write strSQL 
'response.end
conn.execute(strSQL)
 
Next
 
conn.close
set conn = nothing
 
%>
=====================================
=====================================
This is the 2nd code, that gives the above error if 
you send the wrong amount of record to it.
=====================================
<%@ Language = "VBScript"%>
<%
 
dim conn
dim rs
dim strconn
dim strsql
 
strsql = ""
 
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("test1.mdb") & ""
set conn = server.createobject("adodb.connection")
conn.open strconn
uid = request.QueryString("id")
'For x = 1 to 10	
strSQL = "UPDATE linksref SET [linksref].[Ordered] = " & request.Form("order" & x) & " WHERE (linksref.pid=" & uid & " AND [linksref].[urlid]=" & request.Form("urlid" & x) & ")"
 
	response.write strSQL & "<br>"
	'response.end 
	conn.execute(strSQL)
Next
 
conn.close
set conn = nothing
 
%>

Open in new window

Avatar of hielo
hielo
Flag of Wallis and Futuna image

On the second statement, your For is commented out, so there is no x.
Perhaps you should be assigning something from the form:
Dim x
x=Request.Form("recordid")

to update a specific record. IF so, you need to comment the "Next" as well
Avatar of Wayne Barron

ASKER

Hello hielo

Could you perhaps show this code in how it would look, with what I already have?

I believe this would be the right way for it to be done in the form
<<input type="hidden" name="recordedid" value="<%=rs("pid")%>">
(Would that be correct?)
yes. Then "recordedid is what you would use to query your db. That would really not be helpful if you have multiple rows. If you have a dropdown and make a change on the selection of the dropdown, then you need to update the value for that specific dropdown.
<input type="hidden" id="recordedid" name="recordedid" value=""/>
<select name="order1" onchange="setRecordedId(this.name)">...</select>
<select name="order2" onchange="setRecordedId(this.name)">...</select>
<select name="order3" onchange="setRecordedId(this)">...</select>
 
<script>
 function setRecordedId(sel){
  document.getElementById("recordedid").value = sel.name.replace(/\D/g,"");
  sel.form.submit();
}
</script>
 
So, every time a new value is changed, the javascript function is called, which in turn updates the value of the hidden field and auto-submits. If you do not want the autosumbit because you want to do various selections before submitting, then that function would be useless to you. Instead you would need to include checkboxes in your markup and set the value of the checkboxes to rs("pid")

Open in new window

I guess I am lost.

Since this is Dynamic, I cannot do this:
<select name="order1" onchange="setRecordedId(this.name)">...</select>
<select name="order2" onchange="setRecordedId(this.name)">...</select>
<select name="order3" onchange="setRecordedId(this)">...</select>

As, it is done on it's own.
I can do something like this: to this ComboBox.
<select name="order<%=x%>" onchange="setRecordedId(this.name)">...</select>
But since there is only 1 instance in the HTML code, I cannot do the others.
Or am I missing something here?

If possible, could you post some working code of this function working?
Just use the code demo, that you downloaded from my previous post.

Thanks hielo
>>... I cannot do this:...
I was not expecting you to hardcode the values. I just showed that because ultimately that is what the browser "sees". But yes, this is what I was expecting you to code:

<select name="order<%=x%>" onchange="setRecordedId(this.name)">...</select>
 
>>But since there is only 1 instance in the HTML code, I cannot do the others.
Or am I missing something here?
I don't understand what that means. I was expecting you to be iterating over some recordset and be generating that <select> code:
 
While NOT rs.EOF
 Response.Write("<select onchange='setRecordedId(this.name)' onchange="" name='order" & rs.Fields("pid").value & "'>...</select>")
 rs.MoveNext()
Wend

Open in new window

While NOT rs.EOF
 Response.Write("<select onchange='setRecordedId(this.name)' onchange="" name='order" & rs.Fields("pid").value & "'>...</select>")
 rs.MoveNext()
Wend


No sure this is going to do it.
The    name='order" & rs.Fields("pid").value & "'

pid = Page ID #
Not the Order # information.
Order = Ordered

Either way it is written out I receive the following error>

ADODB.Field error '80020009'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/Test/EE/Q_24090342/Update.asp, line 0
Sorry.
Fixed that error.
But it is still not inserting.

This is what my code looks like now.


This is the Update.asp
=========================================================
<form action="Update_Insert.asp?id=<%=Request.QueryString("id")%>" method="post" name="UpdateMyInfo">
    <tr>
	     <td colspan='2'>Order URL List - There are <%=rs.RecordCount%> Then</td>
	</tr>
	<tr>
	     <td colspan='2'>Site Name</td>
         <td>URL</td>
         <td>Order</td>
    </tr>
 
<% 
x = 1
rs.movefirst
Do While NOT rs.EOF 
While NOT rs.EOF
 
 
%>
         <tr>
		      <td colspan='2'>
			       <input type="hidden" name="pid<%=x%>" value="<%=rs("pid")%>">
                   <input type="hidden" name="urlid<%=x%>" value="<%=rs("urlid")%>">
                   <input type="hidden" id="recordedid" name="recordedid" value=""/>
				 <%=rs("urlid")%>&nbsp;&nbsp;<%=rs("urlname")%>
			  </td>
              <td><a href="<%=rs("urlstring")%>" target="_blank"><%=rs("urlstring")%></a></td>
              <td>
             
              <%
 
 Response.Write("<select onchange='setRecordedId(this.name)' onchange="" name='order" & rs.Fields("ordered").value & "'>...</select>")
%>
             
              <select name="order<%=x%>" style="font: 8pt verdana;" onchange="setRecordedId(this.name)">
              <option value="<%=rs("Ordered")%>"><%=rs("Ordered")%></option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              <option value="10">10</option>
                            </select>
</td>
		 </tr>	
 
	<tr>
	     <td colspan='2' align='center'>
		      <input type='hidden' name='state' value='add'>
			  <input type='hidden' name='x' value='<%=x%>'>
    <%
	x=x + 1 ' this will give each Input Name=feature# a Unigue Number
    rs.MoveNext
	Wend
	Loop
	end if
%>
			  <input type='Submit' value='Submit'>
		 </td>
	</tr>
 
</form>
===================================================
This is the update_insert.asp
===================================================
<%@ Language = "VBScript"%>
<%
 
dim conn
dim rs
dim strconn
dim strsql
 
strsql = ""
 
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("test1.mdb") & ""
set conn = server.createobject("adodb.connection")
conn.open strconn
uid = request.QueryString("id")
'For x = 1 to 3' You must have 10 Record to Update, if not you will get an error.
'For x = 1 to 50
Dim x
x=Request.Form("recordedid")
	
strSQL = "UPDATE linksref SET [linksref].[Ordered] = " & request.Form("order" & x) & " WHERE (linksref.pid=" & uid & " AND [linksref].[urlid]=" & request.Form("urlid" & x) & ")"
 
	response.write strSQL & "<br>"
	'response.end 
	conn.execute(strSQL)
'Next
 
conn.close
set conn = nothing
 
%>

Open in new window

And if you remove: (Which was suppose to be removed in the code above)
<select name="order<%=x%>" style="font: 8pt verdana;" onchange="setRecordedId(this.name)">

It does not capture the information from the Database.
Based on you original question:
>>Do While NOT rs.EOF
>>While NOT rs.EOF
why do you have these back to back. That is just not right. I am also seeing

<input type="hidden" name="pid<%=x%>" value="<%=rs("pid")%>">
<input type="hidden" name="urlid<%=x%>" value="<%=rs("urlid")%>">
<input type="hidden" id="recordedid" name="recordedid" value=""/>
 
which we had already discussed? Originally we had discussed including:
<input type='hidden' name='row' value='<%=row%>'>
 
in update.asp, then in Update_Insert.asp you need to use:
For x = 1 to Request("row")
 
instead of	
'For x = 1 to 10
 
That code was already the db for all the records on the webpage upon submission? Have your requirements changed?

Open in new window

Sorry, I had to start a new page, to make sure that everything that I was doing was right.
And I forgot to add in the
<input type='hidden' name='row' value='<%=row%>'>
(Which is why I was never getting my count right)
And in the update.asp
For x = 1 to Request("row")
That I was never to sure on.

Right now with both in place, I am getting this:

Microsoft VBScript runtime error '800a000d'

Type mismatch: '[string: "1, 2, 3, 4, 5, 6, 7,"]'

/Test/EE/Q_24090342/Update_Insert.asp, line 16

Which line 16 is:
For x = 1 to Request("row")

-------------------
And yes, I am working on a project for the person of whom you made your post to.
There was certain things that I could not figure out, and since I was the one that he wanted to work with, I decided that I would get help on my own.
But he knows that I have been getting help on certain aspects.
Like this issue.

You help me.
I help him.
That is the way EE is, Love it.

So, to you hielo
Thanks for the help thus far.
>>I had to start a new page,
OK, but on the previous question, I posted Update_Insert.asp. You can use that as your "guide".
As for:
Type mismatch: '[string: "1, 2, 3, 4, 5, 6, 7,"]' 
 
I don't know how you are getting that. Most likely your underlying source code is generating Multiple:
<input type="hidden" name="row" value="1"/>
<input type="hidden" name="row" value="2"/>
...
<input type="hidden" name="row" value="7"/>
 
If that is the case (and I am 99% sure it is), then based on what you have now, instead of:
For x = 1 to Request("row")
 
do:
Dim row
row =Split(Request("row"), ", ")
For x = 1 To row
 
NOTE, this: =>[string: "1, 2, 3, 4, 5, 6, 7,"]' 
clearly shows that you have a string where the items are separated by "comma space", NOT just a comma. So the Split() function above uses a "comman space" as the element delimiter. If you use just a comma it will not work as you expect.

Open in new window

hello hielo

I added in
row =Split(Request("row"), ", ")
For x = 1 To row

I get the following error

Microsoft VBScript runtime error '800a000d'

Type mismatch

/Test/EE/Q_24090342/Update_Insert.asp, line 17

This is line: 17          For x = 1 To row
sorry, should have been:
For x = 1 To UBound(row)

Not sure if that trailing comma will give you problems, so try using:
For x = 1 To UBound(row)-1

That should at least give you 1..6

Alternatively, you can use a For Each instead of a For...To:

row =Split(Request("row"), ", ")
For Each pid in row
 'pid contains the value you seek

Next
I get a
Type mismatch: 'UBound'
>>I get a. Type mismatch: 'UBound'
That would happen if the page you are submitting FROM contains only ONE:
<input type="hidden" name="row" value="10">
 
IF that is the case, then simply use:
For i=1 to Request("row")
...
Next
 
But if you have multiple:
<input type="hidden" name="row" value="1">
...
<input type="hidden" name="row" value="10">
 
THEN you can use:
Dim row
row =Split(Request("row"), ", ")
For x = 1 To UBound(row)
...
Next

Open in new window

OK
row =Split(Request("row"), ", ")
For x = 1 To UBound(row)

Got rid of the error and runs.
BUT the problem still exist.

If you try to pass 5 records, it will give you
Microsoft JET Database Engine error '80040e14'

Syntax error in UPDATE statement.

/Test/EE/Q_24090342/Update_Insert.asp, line 29
line 29:  conn.execute(strSQL)

If you pass 10 records it will work like it is suppose to.
Why? that is the big question here.

(See this is why I ask a question outside the other persons question. This way I can get help trying to figure things out with the code part, so that I can give other person a good working code.
Thus the reason why he asked: Carrzkiss (for help) )

Anyway, just that I would add that in.
hielo

Why are you posting in the other Question?
As you can see on that question it is: Hello Carzkiss

If I would have ask you to come in, that would be a different story.
That is why I have this question, so that you can assist me with the issue.
Then me assist the other user.....

What is going on?
How are you "passing" the records? If your records are NOT sequential, then you may run into problems because here:
For x = 1 To UBound(row)

you are relying on a unique record identifier per row and that they exist in sequential order in the db.

If you have:
<select name="order1">...</select>
<select name="order2">...</select>
<select name="order4">...</select>
<select name="order5">...</select>
<select name="order6">...</select>

Then:
For x = 1 To UBound(row)
will "count" up from 1...5, but there is NO "order3", so that will break your code.

Have you downloaded the code project?

OK.
You see all the URLs.
You choose like so:

URL# 1
URL# 2
URL# 4
URL# 6
URL# 7
URL# 9

You submit just them records into the db.
That is what he is trying to accomplish.
Wanting to either send 1 (or) 50 records to the DB.

This is the updated code that I have
http://www.pcitdad.com/Test/EE/Q_24090342/Q_24090342.zip

Run
Update.asp?pid=1
(Updated different from what I submitted to the other post)
When you run it

Try to submit it, and you will be given the error that I am referring too.

I have tried your codes, and they are not working.

Anyway, here is the link to download the updated update.asp page
Along with the db and other pages.
http://www.pcitdad.com/Test/EE/Q_24090342/Q_24090342.zip
I haven't seen your files, but I believe your problem is that you are not selecting a value from the select list. When you have this:

<select>
 <option value="<%=rs("Ordered")%>"><%=rs("Ordered")%></option>
...
</select>
 
that does NOT make the first option a "selected" option. So you are essentially NOT sending any value for the select lists, making your sql invalid. This is what I tried:
 
<%@ Language=VBScript %>
<% 
dim conn
dim rs
dim strsql
dim strconn
 
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("/Databases/test1.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
set rs = server.createobject("adodb.recordset")
 
uid = request.QueryString("id")
If "" = Trim(uid) Then
	Response.Write("No id specified")
	Response.End
End IF
 
strsql = "SELECT TOP 2 linksref.urlid, linksref.pid, linksref.Ordered, Links.urlid, Links.urlname, Links.urlstring, Links.Active FROM linksref INNER JOIN Links ON linksref.urlid = Links.urlid WHERE linksref.pid="&uid&" Order by linksref.urlid"
rs.open strsql, conn
If rs.RecordCount <> 0 Then
%>
 
<html>
<head>
    <title>Ordered</title>
    <style>
TD
{
    font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 8pt;
	color: #000000;
	font-weight: normal
}
</style>
</head>
<body>
<table width="900" border="0" bgcolor="LightSteelBlue" cellspacing="1" align="center">
<form action="Update_Insert.asp?id=<%=Request.QueryString("id")%>" method="post" name="UpdateMyInfo">
    <tr>
	     <td colspan='2'>Order URL List - There are <%=rs.RecordCount%> Then</td>
	</tr>
	<tr>
	     <td colspan='2'>Site Name</td>
         <td>URL</td>
         <td>Order</td>
    </tr>
 
<% 
rs.movefirst
Do While NOT rs.EOF 
 
 
%>
         <tr>
		      <td colspan='2'>
			       <!-- the urlid DOES change per record, so for these you do generate one
				  hidden field per record -->
                   <input type="hidden" name="urlid" value="<%=rs("urlid")%>">
                   
				 <%=rs("urlid")%>&nbsp;&nbsp;<%=rs("urlname")%>
			  </td>
              <td><a href="<%=rs("urlstring")%>" target="_blank"><%=rs("urlstring")%></a></td>
              <td>
             
              <select name='order<%=rs("urlid")%>' style="font: 8pt verdana;">
		    <%
		    For i =1 To 10
		    		If i=rs("Ordered") Then
					Response.Write("<option selected='selected' value='" & i & "'>" & i & "</option>")
				Else
					Response.Write("<option value='" & i & "'>" & i & "</option>")
				End If
		    Next
		    %>
              </select>
</td>
		 </tr>	
 
	<tr>
	     <td colspan='2' align='center'>
		      <input type='hidden' name='state' value='add'>
    <%
    rs.MoveNext
	Loop
	end if
%>
	<!-- All your records have the same pid so you do not need to do one hidden pid per record 
	Also, the value of the pid is the same as uid, so just use that instead and DO NOT retrieve that
	value from your db - you already know the value. you are just wasting resources if you do so.
	-->
	<input type="hidden" name="pid" value="<%=uid%>">
			  <input type='Submit' value='Submit'>
		 </td>
	</tr>
 
</form>
</table>
 
 
NOTICE: I used "SELECT TOP 2..." So that I don't get the default three records. I was trying to simulate a changing number of rows. I'll see what you have.

Open in new window

In the files you have, this:
<option value="<%=rs("Ordered")%>"><%=rs("Ordered")%></option>
 
should really be:
<option selected="selected" value="<%=rs("Ordered")%>"><%=rs("Ordered")%></option>

Open in new window

In your Update_Insert.asp, you also need to make sure that valid value was chosen. For example, if the user selected "Please Choose" and then submitted, that would give you a runtime error:
'Update_Insert.asp
...
For x = 1 To UBound(row)
 If "" <> Trim( request.Form("order" & x) ) Then
 
 
   strSQL = "UPDATE links SET [links].[Ordered] = " & request.Form("order" & x) & " WHERE (links.pid=" & uid & " AND [links].[urlid]=" & request.Form("urlid" & x) & ")"
	response.write strSQL & "<br>"
	conn.execute(strSQL)
 End If
Next
...

Open in new window

For x = 1 To UBound(row)


Microsoft VBScript runtime error '800a000d'

Type mismatch: 'UBound'

/Test/EE/Q_24090342/Update_Insert.asp, line 18
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thought it worked, but it does not.
It does not have the [Limited] not more. (Which is Great)
BUT, it still does the same thing as before.
It will not Update the last record in the list.

So. Back to the drawing board.
it displays
UPDATE linksref SET [linksref].[Ordered] = 5 WHERE (linksref.pid=1 AND [linksref].[urlid]=2)
UPDATE linksref SET [linksref].[Ordered] = 1 WHERE (linksref.pid=1 AND [linksref].[urlid]=2)
UPDATE linksref SET [linksref].[Ordered] = 10 WHERE (linksref.pid=1 AND [linksref].[urlid]=2)
UPDATE linksref SET [linksref].[Ordered] = 7 WHERE (linksref.pid=1 AND [linksref].[urlid]=1)
UPDATE linksref SET [linksref].[Ordered] = 9 WHERE (linksref.pid=1 AND [linksref].[urlid]=7)

Which is what I choose to update.
But it will not update the database.


Same code as what you have here.
I have not changed anything but the Database location and name from
test2 - test1
are you sure conn.execute(strSQL) is not commented out? if the db has write permissions then it should update. The other thing you need to check for is the field types. If in your db [linksref].[Ordered] is a Text field ( as opposed to a Number  field), then you should really be using:
SET [linksref].[Ordered] = '5'
It is a Nunber Field.

I went a different path on this one.
I am using a Input Field that retrieves the values from the ComboBox.
It works right well.

I will post the code here later on this weekend.

Have a good weekend.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial