我仍然是ASP编程的新手,我很难确定如何比较客户端和数据库中的值。
例如,我要在数据库中插入date
,starttime
和room
值,但是在一种情况下,它们与date
不能相同,数据库中已经存在starttime
和room
个值。
非常感谢!
答案 0 :(得分:0)
首先查看表中是否已存在类似条目。如果仅在表中不存在类似条目,则可以将其提供给databse。
进行如下查询:
SELECT * FROM yourTable WHERE date = yourDate AND starttime = yourStarttime AND room == yourRoom
如果以上查询返回的结果为NULL
,则进入数据库,否则跳过输入操作。
答案 1 :(得分:0)
if exists(select * from tablename where date = date and starttime = starttime and date=date)
begin
--- insert (here It Check data is There If there in begin statement U can insert
end
else
begin
--if any operation if No data there
end
或
if exists(select * from tablename where date = date and starttime =
starttime and date=date)
begin
declare @count int ;
set count= select count(*) from tablename where date = date and starttime=starttime and date=date
if(@count ==0 )
begin
-- Count is Zero
--- insert (here It Check data is There If there in begin statement U can
end
else
begin
-- Count more than Zero
end
end
else
begin
--if any operation if No data there
end