Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Type Mismatch" Error on AccessDB/ASP Update SQL Statement 1

Status
Not open for further replies.

tgilbreath

Programmer
Mar 11, 2003
10
US
Hi guys-

Not sure what's going on here...I've got a dropdown box populated from a DB...I have all this code that is supposed to update the record. But it keeps giving me :

--------------------------------------------
Microsoft VBScript runtime error '800a000d'

Type mismatch

/admin/resource_update.asp, line 49
--------------------------------------------

The DSN is correct, because the connection is being made...but here is the line it's talking about: (49):

<input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;<%=RS(&quot;ID&quot;)%>&quot;>





Here is the code for the page &quot;resource_update.asp&quot;:

<%@Language=VBScript%>
<%Response.Buffer=True%>

<html>
<body>

<%
Dim MyConn, SQL, RS, id, Items

Set MyConn=Server.CreateObject(&quot;ADODB.Connection&quot;)
MyConn.Open &quot;DSN=ticktock-resources&quot;
SQLStmt = &quot;SELECT * &quot;
SQLStmt = SQLStmt & &quot;FROM Items &quot;
Set RS = MyConn.Execute(SQLStmt )
%>

<form action=&quot;resource_update.asp&quot; method=&quot;Post&quot;>
<select name=&quot;ID&quot;>

<%While Not RS.EOF%>
<option value=&quot;<%=RS(&quot;ID&quot;)%>&quot;>
<%=RS.Fields(&quot;Items&quot;)%>

<%
RS.MoveNext
Wend

RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
%>

<input type=&quot;submit&quot; value=&quot;Select&quot;>
</select>
</form>

<%
id = Request(&quot;ID&quot;)

If id <> &quot;&quot; Then

Set MyConn=Server.CreateObject(&quot;ADODB.Connection&quot;)
MyConn.Open &quot;DSN=ticktock-resources&quot;

%>

<form action=&quot;resource_update2.asp&quot; method=&quot;Post&quot;>
<input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;<%=RS(&quot;ID&quot;)%>&quot;>
Items<input type=&quot;text&quot; name=&quot;item&quot; size=&quot;20&quot; value=&quot;<%=RS(&quot;Items&quot;)%>&quot;><br>
<input type=&quot;submit&quot; value=&quot;Update&quot;>

<%
RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing

Else
Response.Write &quot;<p>Please Select a Record&quot;
End If
%>

</body>
</html>






Now here is the code for the page that actually does the work, resource_update2.asp:


<%@Language=VBScript%>
<%Response.Buffer=TRUE%>

<html>
<body>

<%
item = Replace(Request.Form(&quot;Items&quot;), &quot;'&quot;, &quot;''&quot;)
id = CStr(Request.Form(&quot;ID&quot;))

Set MyConn=Server.CreateObject(&quot;ADODB.Connection&quot;)
MyConn.Open &quot;DSN=ticktock-resources&quot;
SQL=&quot;Update tblItems Set Items = '&quot;&items&&quot;'' Where [ID] = &quot;&id&&quot;&quot;
Set RS = MyConn.Execute(SQLStmt )




MyConn.Execute(SQL)
MyConn.Close
Set MyConn = Nothing


Response.Redirect &quot;resource_update.asp&quot;
%>

</body>
</html>








Any help would be appreciated!!! :)

Tim


 
Look well the first page you post : you close everything in the middle of the page :
Code:
RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
... then try to use RS again after. Your error may comes from here. Water is not bad as long as it stays out human body ;-)
 
Ok dude your problem is (many) but I'll answer your VBScript error first:

<input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;<%=RS(&quot;ID&quot;)%>&quot;>

The reason this above line is not working is becuase you have the recordset closed and set to nothing before you hit this line.

Additional problems: (Update1.asp)

Do not name your Select Box and the Hidden field the same &quot;ID&quot;.

You could really structure your code better, as you only need to open your connection to the DB one time not twice and you only need to close it once also.

Additional problems: (Update2.asp)

<%@Language=VBScript%>
<%Response.Buffer=TRUE%>

<html>
<body>

<%
item = Replace(Request.Form(&quot;Items&quot;), &quot;'&quot;, &quot;''&quot;)
id = CStr(Request.Form(&quot;ID&quot;))

Set MyConn=Server.CreateObject(&quot;ADODB.Connection&quot;)
MyConn.Open &quot;DSN=ticktock-resources&quot;
SQL=&quot;Update tblItems Set Items = '&quot;&items&&quot;'' Where [ID] = &quot;&id&&quot;&quot;
Set RS = MyConn.Execute(SQLStmt )
*Why do you need this above line when you don't use the recordset, unless you left some code out?


MyConn.Execute(SQL)
MyConn.Close
Set MyConn = Nothing


Response.Redirect &quot;resource_update.asp&quot;
%>

</body>
</html>

&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Thanks for the help guys....that cleared up THAT error..now, upon selecting an entry from the dropdown, I get this:


ADODB.Field error '80020009'

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

/admin/resource_update.asp, line 0




I have changed the hidden field name for ID to &quot;id2&quot; and changed the corresponding reference on update2.asp. I also took the SQL RS statement out of the second page like you mentioned. What else could be causing this new error?

T
 
As MrGreed says, your code is ... haw to say ??? ... a little bit dirty. ;-)

Try to format correctly the genarated HTML :
- closing the options tags
- outing the submit buton from select tag that can only content options tags.

Try that and tell me if it works better :
Code:
<form action=&quot;resource_update.asp&quot; method=&quot;Post&quot;>
<select name=&quot;ID&quot;>

<%While Not RS.EOF%>
<option value=&quot;<%=RS(&quot;ID&quot;)%>&quot;>
<%=RS.Fields(&quot;Items&quot;)%>
</option>
Code:
<%
RS.MoveNext
Wend

RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
%>
<input type=&quot;submit&quot; value=&quot;Select&quot;>
Code:
</select>
<input type=&quot;submit&quot; value=&quot;Select&quot;>
Code:
</form>
Water is not bad as long as it stays out human body ;-)
 
ok,

Because when your code hits:

<input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;<%=RS(&quot;ID&quot;)%>&quot;>
Items<input type=&quot;text&quot; name=&quot;item&quot; size=&quot;20&quot; value=&quot;<%=RS(&quot;Items&quot;)%>&quot;><br>
<input type=&quot;submit&quot; value=&quot;Update&quot;>

Your recordset is already at the end of file, from your while loop above.

You should store the &quot;ID&quot; and &quot;ITEMS&quot; value in variables of what record you want then use those variables instead of the recordset.

&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Hey, MrGreed, I never sayed &quot;Minkey&quot; !!!
LOL LOL LOL Water is not bad as long as it stays out human body ;-)
 
Just another hint, though this won't fix your current error...

Things like:
Code:
SQL=&quot;Update tblItems Set Items = '&quot;&items&&quot;'' Where [ID] = &quot;&id&&quot;&quot;
Can be dangerous. In order to ensure that you get the results you want (string concatentation) always uses spaces around the &quot;&&quot; operator:
Code:
SQL=&quot;Update tblItems Set Items = '&quot; & items & &quot;'' Where [ID] = &quot; & id & &quot;&quot;
You never know when some &hxxx sequence of characters is going to be interpreted as a hex literal instead.

I also seem to see a variable SQL and another SQLStmt in places - check on that.

And the big question:

Where is your
Code:
Option Explicit
and your variable declaration (
Code:
Dim
) statement? Leaving them out is just asking for trouble.
 
A Star for you dilettante for the &quot;Option explicit&quot; remark. It's always good to say and say it again. Water is not bad as long as it stays out human body ;-)
 
Now if I could stop forgetting them myself.

Like most people I mean well... but I'm far from perfection, so far I can't see it from where I'm standing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top