2 Attachment(s)
[Resolved] Can ADD and DELETE from mDB but not UPDATE..?!?!
This is the code i use to UPDATE within my page.. but it doesnt update anything, it doesnt do anything, nor doest it trow any errors..
Can someone look over my code (i'll upload the ASP page,and the mdb)
(PS: the DB was renamed to .txt , because the upload system here doesnt accept .mdb as extension...dunno why??)
Here's the code that create's the "problem" (it doesnt update the DB)
Code:
ELSEIF Request.Form("flag")="2" THEN
SQLstmt = "UPDATE Produkter SET "
SQLstmt = SQLstmt & "Varenavn='" & TRIM(Request.Form("Varenavn")) & "', "
SQLstmt = SQLstmt & "Varenummer='" & TRIM(Request.Form("Varenummer")) & "', "
SQLstmt = SQLstmt & "Varepris='" & TRIM(Request.Form("Varepris")) & "', "
SQLstmt = SQLstmt & "Varetekst='" & TRIM(Request.Form("Varetekst")) & "', "
SQLstmt = SQLstmt & " WHERE ID=" & TRIM(Request.Form("Recordid"))
Re: Can ADD and DELETE from mDB but not UPDATE..?!?!
Hi,
If its not thortwing any errors at alll and the code is not updating or transacting to teh MDB, then it is probably the connectionstring or the connection itself is not executing at all, therefore not executing the statement. check the following.
1. any case or boolean ilogical statements that may be in operation to trigger the instance off, they may be not triggereing, the string literals may be incorrect, or a naming convention could be at fault.
2. If in the event that your connection string is in a function or class, make sure that the class is properly instantiated or initialised when needed or prompted by your application.
3. Check any execution statements that triggers the query off such as your recordset or your connection object, they may be at fault or not instantiating properly.
Check these points and get back to me.
Hope this helps
Kai
1 Attachment(s)
Re: Can ADD and DELETE from mDB but not UPDATE..?!?!
Well.. my connection and all is OK.. but now that i changed some stuff, it trows me an error
See below code that should do the UPDATE..
(or download the DB from the prev post + the ASP in this post...and try yourself)
Quote:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntakserror in UPDATE-string
/ASPnettbutikk/butikk.asp, linje 127
VB Code:
'If the QueryString has the Actionvar = update then generate
'the page for updating items
ELSEIF Actionvar="update" THEN
IF Len(TRIM(Request.Form("flag"))) = 0 THEN
SQLstmt = "SELECT * FROM Produkter WHERE ID=" & Request.QueryString("Recid")
%>
<HR>
<!--
SQL statement: <%=SQLstmt%>
<HR>
-->
<%
Set rs = conn.Execute(SQLstmt)
IF NOT RS.EOF THEN
%>
<font color="red">Rediger dette produktet</font>
<FORM METHOD="post" ACTION=" butikk.asp?Actionvar=update">
<B>Varenavn:</B> <INPUT TYPE="text" NAME="Varenavn" VALUE="<%=rs("Varenavn")%>"><BR>
<B>Varenummer:</B> <INPUT TYPE="text" NAME="Varenummer" VALUE="<%=rs("Varenummer")%>"><BR>
<B>Varepris:</B> <INPUT TYPE="text" NAME="Varepris" VALUE="<%=rs("Varepris")%>"><BR>
<B>Varetekst:</B> <INPUT TYPE="text" NAME="Varetekst" VALUE="<%=rs("Varetekst")%>"><BR>
<INPUT TYPE="hidden" NAME="flag" VALUE="2">
<INPUT TYPE="hidden" NAME="Recordid" VALUE="<%=rs("ID")%>">
<INPUT TYPE="submit" VALUE="Lagre endringer">
</FORM>
<%
rs.MoveNext
rs.Close
END IF
'ELSEIF Request.Form("flag")="2" THEN
' SQLstmt = "UPDATE Prices SET "
' SQLstmt = SQLstmt & "Varenavn='" & TRIM(Request.Form("Varenavn")) & "', "
' SQLstmt = SQLstmt & "Varenummer='" & TRIM(Request.Form("Varenummer")) & "', "
' SQLstmt = SQLstmt & "Varepris=" & TRIM(Request.Form("Varepris"))
' SQLstmt = SQLstmt & " WHERE ID=" & TRIM(Request.Form("Recordid"))
ELSEIF Request.Form("flag")="2" THEN
SQLstmt = "UPDATE Produkter SET "
SQLstmt = SQLstmt & "Varenavn='" & TRIM(Request.Form("Varenavn")) & "', "
SQLstmt = SQLstmt & "Varenummer=" & TRIM(Request.Form("Varenummer")) & ", "
SQLstmt = SQLstmt & "Varepris=" & TRIM(Request.Form("Varepris")) & ", "
SQLstmt = SQLstmt & "Varetekst='" & TRIM(Request.Form("Varetekst")) & "', "
SQLstmt = SQLstmt & " WHERE ID=" & TRIM(Request.Form("Recordid"))
%>
<HR>
<!--
SQL statement: <%=SQLstmt%>
<HR>
-->
<%
Conn.Execute (SQLstmt)
response.write SQLstmt & "<br>"
Response.Write "Varen er nå blitt redigert!<br><A HREF=""butikk.asp"">Gå tilbake..</A>"
END IF
Re: Can ADD and DELETE from mDB but not UPDATE..?!?!
Hi,
right then, were getting somewhere now..
VB Code:
'ELSEIF Request.Form("flag")="2" THEN
' SQLstmt = "UPDATE Prices SET "
' SQLstmt = SQLstmt & "Varenavn='" & TRIM(Request.Form("Varenavn")) & "', "
' SQLstmt = SQLstmt & "Varenummer='" & TRIM(Request.Form("Varenummer")) & "', "
' SQLstmt = SQLstmt & "Varepris='" & TRIM(Request.Form("Varepris")) & "',"
' SQLstmt = SQLstmt & " WHERE_ID='" & TRIM(Request.Form("Recordid")) &"'"
As you can see, ive made some changes to your statement.
1. the WHERE_ID never use spaces in your tables at all. So change this for what ive substituted adn youre away.
2. Plus you missed some single quotes out and I have added them...
try this and see how you get on.
Kai
Re: Can ADD and DELETE from mDB but not UPDATE..?!?!
I get a new error here..
Feiltype:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] For få parametere. Ventet 1.
/ASPnettbutikk/butikk.asp, linje 137
(too few parameters. expected 1)
Re: Can ADD and DELETE from mDB but not UPDATE..?!?!
PS: this is the connectionstring i want to use, u used a commented out one..
VB Code:
ELSEIF Request.Form("flag")="2" THEN
SQLstmt = "UPDATE Produkter SET "
SQLstmt = SQLstmt & "Varenavn='" & TRIM(Request.Form("Varenavn")) & "', "
SQLstmt = SQLstmt & "Varenummer=" & TRIM(Request.Form("Varenummer")) & ", "
SQLstmt = SQLstmt & "Varepris=" & TRIM(Request.Form("Varepris")) & ", "
SQLstmt = SQLstmt & "Varetekst='" & TRIM(Request.Form("Varetekst")) & "', "
SQLstmt = SQLstmt & " WHERE ID=" & TRIM(Request.Form("Recordid"))
Re: Can ADD and DELETE from mDB but not UPDATE..?!?!
Quote:
Originally Posted by kaihirst
Hi,
right then, were getting somewhere now..
VB Code:
'ELSEIF Request.Form("flag")="2" THEN
' SQLstmt = "UPDATE Prices SET "
' SQLstmt = SQLstmt & "Varenavn='" & TRIM(Request.Form("Varenavn")) & "', "
' SQLstmt = SQLstmt & "Varenummer='" & TRIM(Request.Form("Varenummer")) & "', "
' SQLstmt = SQLstmt & "Varepris='" & TRIM(Request.Form("Varepris")) & "',"
' SQLstmt = SQLstmt & " WHERE_ID='" & TRIM(Request.Form("Recordid")) &"'"
As you can see, ive made some changes to your statement.
1. the WHERE_ID never use spaces in your tables at all. So change this for what ive substituted adn youre away.
2. Plus you missed some single quotes out and I have added them...
try this and see how you get on.
Kai
Slow down there trigger....
The WHERE ID wasn't a FIELD name.... it was his WHERE clause. WHERE ID = 12.
Assuming ID is in fact a number, the lack of quotes on it is correct.
OKay... but we are getting somewhere.... Even though you've specified the table to be updated in the UPDATE clause, because you are using a WHERE clause, you have to specify the FROM caluse as well.... as silly as it seems, it should be done.
-- strike that... I see the problem....
VB Code:
ELSEIF Request.Form("flag")="2" THEN
SQLstmt = "UPDATE Produkter SET "
SQLstmt = SQLstmt & "Varenavn='" & TRIM(Request.Form("Varenavn")) & "', "
SQLstmt = SQLstmt & "Varenummer=" & TRIM(Request.Form("Varenummer")) & ", "
SQLstmt = SQLstmt & "Varepris=" & TRIM(Request.Form("Varepris")) & ", "
SQLstmt = SQLstmt & "Varetekst='" & TRIM(Request.Form("Varetekst")) & "', " <-- see this comma right here? It shouldn't be there. Dump it.
SQLstmt = SQLstmt & " WHERE ID=" & TRIM(Request.Form("Recordid"))
I didn't see that until I was pasting your code it... then it stood out.... The last coma after the last field being updated is not needed as there are no more fields listed after it.
-tg
Re: Can ADD and DELETE from mDB but not UPDATE..?!?!
Well.. It turned out that TECHGNOME was right, but thanks for all tips and help to you other guys to, learned a lot from links and tips.. thanks
So the right stuff looks like this
Quote:
ELSEIF Request.Form("flag")="2" THEN
SQLstmt = "UPDATE Produkter SET "
SQLstmt = SQLstmt & "Varenavn='" & TRIM(Request.Form("Varenavn")) & "', "
SQLstmt = SQLstmt & "Varenummer=" & TRIM(Request.Form("Varenummer")) & ", "
SQLstmt = SQLstmt & "Varepris=" & TRIM(Request.Form("Varepris")) & ", "
SQLstmt = SQLstmt & "Varetekst='" & TRIM(Request.Form("Varetekst")) & "' "
SQLstmt = SQLstmt & " WHERE ID=" & TRIM(Request.Form("Recordid"))
Re: Can ADD and DELETE from mDB but not UPDATE..?!?!
ARRGGGHH didnt look hard enough at the query!! Cheers Tech....
Teaches me for spending 10 hours coding in the office then come straight home NOT via the pub and stright on the coding forums!!!
NOTE TO SELF.. GET LIFE!!!!!
Kai