473,412 Members | 3,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

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

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.
Jul 29 '06 #1
3 1160
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.

Toni wrote:
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.
Jul 29 '06 #2
"Toni" <no****@hotmail555.comwrote in message
news:uH**************@TK2MSFTNGP02.phx.gbl...

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
Jul 29 '06 #3
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!
*************************************************
"Toni" <no****@hotmail555.comwrote in message
news:uH**************@TK2MSFTNGP02.phx.gbl...
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.

Jul 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: peterlai | last post by:
<html> <head> </head> <body><pre> <?php $connection = odbc_connect("test","root","passwd");
3
by: ·sÂA¤H | last post by:
Hi All, I am a beginner of XML, my final year project is using a XML and JAVA to develop a Workflow Management System. It make me very confuse. I don't even know how to use the XML to exchange...
1
by: Renee | last post by:
I am doing a simple client-side example using DOM in JScript. When the user enter info and click on the submit button, it will then print the value at the bottom of the page. However, I don't know...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
39
by: TonyJeffs | last post by:
Great book - I like the way that unlike other books, AC++ explains as much as possible about every piece of code discussed, so I'm not left thinking, "well...OK... I get line 12, but I wonder what...
19
by: What-a-Tool | last post by:
I have a school project (ASP) in which I have to call three different ASP pages from three different and identical (except for the form "action", obviously) HTM pages. This I have no problem with....
2
by: Kris Krieger | last post by:
Hello, Group, I hope it's OK for me to ask this question here, since I'm a "dabbler", not a "programmer". What I'd like to do, if it's possible, is find a reference or example/template that...
24
by: silversurfer2025 | last post by:
Hello. I do not know whether this really is the right group, but I could not find any group dealing only with GUIs for C++ so here I am. I am currently deciding which GUI to use in my program....
1
by: vocalise | last post by:
The title probably isn't very clear, but I haven't been able to find this problem (or I must be having problems figuring out which search strings to use) so I apologize if this has been addressed...
15
by: JohnDriver | last post by:
Hello I am learning Ajax and I am following the tutorials found but for some reason, my code is not working. I think I am missing something in the code that I am posting below. Please have a look...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.