值只保存在数据库中一次 [英] value save in database only one time

查看:80
本文介绍了值只保存在数据库中一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我有两个文本框。两者都有一些整数值。我想当用户点击保存按钮然后第一次将其保存在数据库中,如果用户传递了一些值,那么它就不会保存在数据库中。

解决方案

因此,在执行插入之前检查它是否在表中,通过使用SELECT返回匹配的记录或返回记录的计数并将其检查为零:

  SELECT  COUNT(*) FROM  MyTable  WHERE  myColumn = MyValu 

你可以创建一个存储过程来检查,然后插入它,如果它不存在,但我宁愿明确地做,并向用户明智地报告问题。


Dear All,

i have two textboxes. both of have some integer value. i want when the user click on the save button then first time its saves in the database next time if the user pass some value then it does't save in the database.

解决方案

So check if it is in the table before you do the insert, by using SELECT to eitehr return matching records or return the count of the records and check it for zero:

SELECT COUNT(*) FROM MyTable WHERE myColumn=MyValu

You could cretae a stored procedure to check and then insert if it doesn't exist, but I'd rather do it expicitly and report a problem to the user sensibly instead.


这篇关于值只保存在数据库中一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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