Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every one,
could you plz help me. I have a Form application (c# vs 2010)with many textboxes. i fill the textboxes from mysql data without any problem.

my question, what is the best way to update only those textboxes that has changed values into the database? i mean,if i made change in textbox1 then my command should be
SQL
update table SET column1 = 'newvalue of textbox1' WHERE ID =@ID)

if i made change in textbox1 and textbox2 then my command should be
SQL
update table SET column1 = 'newvalue of textbox1' , column2 = "new value of textbox2" WHERE ID =@ID)

etc..

it could be very kindly of you, if you can give me an example how i can do that.
thank you.
Posted

There are two levels at which you could possible do this; code or DB. The Db answer involves sending all the fields back one at a time and testing them with:
update table SET column1 = 'newvalue of textbox1' WHERE ID =@ID AND column1 <> 'newvalue of textbox1';

The code way requires the applicaiton to manage the lifecycle of the data and to 'know' when it needs refreshing. (Check out some articles on 'Unit of Work'). Essentially you would keep a list of the fields and whether they are 'dirty', that is contain new or updated information.
 
Share this answer
 
thank you but your answer dont help me to much. do you have an example for me?.
- idee 1
when i click a button (save) then i update only this values in the database of those textboxes, which has new values. how to check, if the current value != orgianl value? and how to build the sql query dynamic . i though i should use dataset ??

- idee 2
when i lost the focus on textbox, i check if the current value != orginal value and if it is true i update the value ?

or is there a better solution?

i would be very nice, if you can send me some code :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900