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.
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.
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
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!
*************************************************
"Toni" <nob...@hotmail555.com> wrote in message
news:uHfoF$vsGHA...@TK2MSFTNGP02.phx.gbl...