我对asp编程还是个新手,很难弄清楚如何将客户端的值与数据库进行比较。
例如,我将把date
、starttime
和room
值插入数据库,但在一个条件下,它们不能与数据库中已经存在的date
、starttime
和room
值相同。
非常感谢!
首先看表中是否已经存在类似的条目。若类似的条目仅在表中不存在,那个么您可以向数据库中提供条目
进行如下类似查询:
SELECT * FROM yourTable WHERE date = yourDate AND starttime = yourStarttime AND room == yourRoom
如果上述查询返回的结果为NULL
,则进入数据库,否则跳过进入操作。
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