如何从文本框更新到mysql数据库 [英] how to update from textboxes into mysql database

查看:101
本文介绍了如何从文本框更新到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
你能帮我吗?我有一个带有许多文本框的Form应用程序(C#与2010).我从mysql数据填充文本框没有任何问题.

我的问题是,仅更新那些已将值更改为数据库的文本框的最佳方法是什么?我的意思是,如果我在textbox1中进行了更改,那么我的命令应该是

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)


如果我在textbox1和textbox2中进行了更改,则我的命令应为


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.

推荐答案

您可以在两个级别上执行此操作;代码或数据库. Db的答案涉及一次将所有字段发送回一个字段,并使用以下命令进行测试:
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.


谢谢,但是您的回答对我没有多大帮助.你有我的榜样吗?
-idee 1
当我单击一个按钮(保存)时,我仅更新那些文本框的数据库中的该值,这些值具有新值.如何检查当前值!= orgianl值?以及如何建立动态SQL查询.我虽然应该使用数据集??

-idee 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 :)


这篇关于如何从文本框更新到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆