This topic is locked
[SOLVED]

 Update Table records from Button

5/19/2014 2:35:30 PM
ASPRunnerPro General questions
J
jmccullough author

I have a database and I would like to be able to click on a button on my View Page that will update the currently logged on user's password in the Userstbl to "XXXXXXX" so that they cannot log back in.
I am using ASPRunner Pro 7.2. I have attempted to create a Customquery putting the code on the Server tab inside of the button but it is not working. Nothing happens when the button is clicked, no errors, no messages.

Here is the code I have behind the button:
CustomQuery("update Userstbl set Password='xxxxx' where UserName='" & Session("Vendor Number") & "'")

result("txt") = "Records were updated."
Is there any additional code that I need anywhere or is this all I need ? Any help would be appreciated.
Thank you.

Admin 5/19/2014

Check this article that explains how to troubleshoot buttons code:

http://xlinesoft.com/blog/2012/05/16/troubleshooting-custom-buttons-in-phprunner-and-asprunnerpro-applications/
You need to print your SQL Query from there to see if it looks correct.

J
jmccullough author 5/20/2014

Have tried your suggestion according to the documentation and this is the error I receive. Can you tell me what it means ?
buttonhandler.asp POST 500 Internal Server Error text/html loadfirst.js:2 Script 613 B 286 B 255 ms 255 ms 255 ms

G
gonzalosb 5/20/2014

Hi jmack,

try this way:



sql = "Userstbl set Password='xxxxx' where UserName=" & Session("Vendor Number")

dbConnection.Execute sql
result("txt") = "Records were updated."


this should work, if you have an error replace ("Vendor Number") with ("Vendor_Number")
sometimes spaces affect the coding

AND PLEASE let me know if works or if you found other way to do it.

J
jmccullough author 5/20/2014

Thank you for the quick reply and suggestion. I added your code as suggested and it still does nothing. No error or message and no table update.
Thank you for the suggestion. I am at a loss.

Admin 5/20/2014

jmack,
you need to post a screenshot that explains what you see under Response tab, similar to screenshot #2 at http://xlinesoft.com/blog/2012/05/16/troubleshooting-custom-buttons-in-phprunner-and-asprunnerpro-applications/

G
gonzalosb 5/20/2014

sorry my bad, i miss the UPDATE on the code:



sql = "Update Userstbl set Password='xxxxx' where UserName=" & Session("Vendor Number")

dbConnection.Execute sql
result("txt") = "Records were updated."


try it now.

J
jmccullough author 5/20/2014

gonzalosb,
Made change but still nothing. Thanks for the suggestion.
Admin, I did screen print of error but when I copy it and try to paste the paste option is grayed out. How do I insert the screenshot ?

Admin 5/20/2014

Upload it somewhere, to Dropbox or to imgur.com

G
gonzalosb 5/20/2014

hmmm, ok try it like this:



DoAssignment Session, button.getCurrentRecord()

sql = "Update Userstbl set Password='xxxxx' where UserName=" & Session("Vendor Number")

dbConnection.Execute sql
result("txt") = "Records were updated."


or



DoAssignment Session, button.getCurrentRecord()

User= Session("Vendor Number")

sql = "Update Userstbl set Password='xxxxx' where UserName=User"

dbConnection.Execute sql
result("txt") = "Records were updated."


or the last one without the DoAssigment line
if still not working, replace - Session("Vendor Number") - from the source and all your coding with - Session("VendorNumber") - all together.

Sometimes the phrases like NUMBER by there own confuse the database.

J
jmccullough author 5/27/2014

Tried all of your suggestion with NO luck. Table is not updated and no message is displayed. I even tried this code from one of your earlier posts. Strange, I get the message that the records were updated but that's all it does, display the message. It doesn't update the Password field to xxxxxxxx.
dim sql, record

DoAssignment record, button.getNextSelectedRecord()

do while isObject(record)

sql = "Update Userstbl set Password='xxxxxxxx' where ID='" & record("VendorNumber") & "'"

dbConnection.Execute sql

DoAssignment record, button.getNextSelectedRecord()

loop

result("txt") = "Records were updated."
Thanks for your help and suggestions.

G
gonzalosb 5/29/2014

that code didnt work for mi ider, this is what i use that work for me



sql = "Update Userstbl set Password='xxxxx' where ID=" & record("ID")

dbConnection.Execute sql

result("txt") = "Records were updated."



this work for sure but in your case you need to get the username from the login instead of an ID from the table.
OOH!!! try replacing ID=" & record("ID") with VendorNumber=" & SESSION("UserName")



sql = "Update Userstbl set Password='xxxxx' where VendorNumber=" & SESSION("UserName")

dbConnection.Execute sql

result("txt") = "Records were updated."


it may be thats why i doesnt work
is the user using his vendor number to login as UserName? if not, replace VendorNumber= with the column name where the Login username is located.

EX: UserName= or LoginName= etc,etc
if still not work, create a separated project only to test the code by it self to be sure nothing is corrupting the code.
Keep diging and keep asking my friend, this code is tricky, take me long to figure it out to me too...

Admin 5/30/2014

Here is what finally worked:

sql = ("UPDATE Userstbl SET Userstbl.[Password] = 'xxxxxxxx' WHERE Userstbl.UserName='"&Session("UserName")&"'")

CustomQuery(sql)

result("txt") = "Records were updated."