Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
update table SET column1 = 'newvalue of textbox1' WHERE ID =@ID)
if i made change in textbox1 and textbox2 then my command should be
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 10-Nov-12 10:03am
hab0123201
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 Smile | :)
  Permalink  

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

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 405
2 Kornfeld Eliyahu Peter 275
3 Gihan Liyanage 163
4 Sibeesh KV 156
0 Sergey Alexandrovich Kryukov 6,775
1 OriginalGriff 6,696
2 CPallini 5,345
3 George Jonsson 3,599
4 Gihan Liyanage 2,751


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100