Beginner's problem: A problem with pre-filled forms

T

Toni

Hello! I'm building an application where the user can update his own
personal information in a database using a form. The program fetches the
user's information from the database, fills the form with this information,
then the user makes the changes that he wants, clicks the "Update" button
and the updated information is sent back to the database. But I have a
problem. My program is supposed to work like this:

txtNamefield.text = "John Smith"
- a text field is filled with old information fetched from the database
- the user changes this name, and clicks "Update"

Dim name as String
name = txtNamefield.text
Dim Sqlsentence as string
Sqlsentence = "UPDATE tableUser SET NAME = '" & name & "' WHERE USERID=XXX;"
- the value of the text field is read to the variable "name" and the
Sqlsentence is executed.

But the value sent to the database is still the same old value, "John
Smith", even though the user changed it and it vas read to the variable
"name".

If I don't fill the textfields in advance the program reads the values
correctly. I would be very happy if someone could let me know what I'm doing
wrong. Thank you very much in advance!

Toni S.
 
C

cannontrodder

I think you are setting the text field every time the page loads
INCLUDING when you post back the changed value.

What you need to do is only set the text field when the page first
loads but not when you click update and it posts back:

If Not Page.IsPostBack Then
'set values from database
End If

PS: Remember that the method you are using is dangerous security-wise
as people could pass sql code through to your page. Using the
validation controls will block this for you.
 
M

Mark Rae

Could it simply be that you're fetching the initial values in the Page_Load
event regardless of whether the page is being opened as a result of a
postback or not...? E.g.

If Not Page.IsPostback
' fetch the initial values - don't do this when updating!
End If
 
M

msnews.microsoft.com

Page_Load() fires prior to button events.

Make sure you are setting the value only when IsPostBack() is false. If not,
you are setting the value again prior to saving, thus saving the original
value.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think Outside the Box!
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top