如何在单键clik上执行插入和更新操作 [英] how to do insert and update operation on single button clik

查看:43
本文介绍了如何在单键clik上执行插入和更新操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我真正想做的是...我想对单个查询进行插入和更新操作。我尝试从表中获取唯一值。

如果唯一值匹配则更新操作将完成..其他明智的插入操作将在运行。





但是我不知道在if语句中使用表中所选列的位置..



please指导我



提前谢谢

Hi everyone,

what i actually want to do is.. i want to do insert and update operation on single query. i tried getting the unique value from table.
if the unique value is matched update operation will be done.. other wise insert operation will in action.


But i don''t know where to use the selected column from the table in If statement..

please guide me

Thanks in advance

推荐答案

如何为它设置存储过程。首先检查值,并根据是否找到值在存储过程中执行插入或更新。
How about having a stored procedure for it. Check the value first and based on whether the value is found or not perform insert or update accordingly in the stored procedure only.


如同Rahul建议您可以检查表中是否存在特定行使用 EXISTS(Transact-SQL) [ ^ ]

这是一个样本

As Rahul suggested you can check if a particular row exists in a table using EXISTS (Transact-SQL)[^]
Here is a sample
IF EXISTS (SELECT 1 FROM YourTable WHERE YourColumn = ValueToCheck)
BEGIN

   --Update Operation

END
ELSE
BEGIN

   --Insert Operation

END





你在存储过程中写这个并传递值来检查作为存储过程的参数。



You write this in a stored procedure and pass the value to check as a parameter to the stored procedure.


i got a solution. created one public string if the string is null do insertion action.
else the string contain value do updation operation


public string new{ get; set; }

new  =  "new";

if(new == "new")
{
------do insert operation--------
}
else
{
-------- do updation operation-------
}

it works fine for me..


这篇关于如何在单键clik上执行插入和更新操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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