使用单个按钮插入/更新记录的最佳方法。 [英] Best method to insert/update record by using single button.

查看:90
本文介绍了使用单个按钮插入/更新记录的最佳方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用单个按钮插入记录以及更新记录到table.which是使用单个按钮插入/更新记录的最佳且不易出错的方式。或者最好使用两个不同的按钮插入和更新?

I want to use a single button to insert records as well as update records to table.which is the Best and less error prone way to insert/update record by using single button.or is it better to use two different buttons for insert and update?

推荐答案

检查按钮单击时记录的ID。如果Id为零,则写入插入记录的逻辑。如果Id大于零,则为更新写入逻辑。

[或]

写一个存储的procrdure,根据记录的Id插入和更新记录。并按下按钮调用存储过程。
Check the id of the record on button click. If the Id is Zero then write the logic for inserting the record. If Id is greater than zero then write logic for the update.
[or]
Write one stored procrdure which inserts and updates the record based on Id of record. And call the stored procedure on button click.


我将使用两个按钮。从用户的角度来看,这将是最好的。



你可以使用一个 Button ,但您需要添加额外的代码来控制其文本和其他属性。然后在插入/更新时,您必须检查用户是否正在尝试插入更新



所以,在我看来,选择两个 Buttons 。简单但有用。 :)
I would go with two Buttons. That would be the best from User point of view.

You can work with one Button, but you need to add extra codes to controls their Texts and other properties. Then while Inserting/Updating, you have to check whether User is trying to Insert or Update.

So, in my opinion, go for two Buttons. Simple, yet useful. :)


使用实体框架。它很简单,可以在单击时执行多项操作。



如果您对ORM感到满意,那么将逻辑移到存储过程。它更好的选择。检查是否存在记录,然后更新其他插入。





否则你的ORM必须足够聪明才能根据行状态创建动态脚本。(您必须保持记录的行状态。)
Use Entity framework. its simple and can do multiple operations on single click.

If you are happy with your ORM, than move logic to store procedure. Its more better option. Check if record exist, then updated else insert.


Otherwise your ORM must smart enough to create dynamic script based on row state.(You must maintain Row state of your record.)


这篇关于使用单个按钮插入/更新记录的最佳方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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