日期:2014-05-18  浏览次数:20522 次

===============怎样判断删除表是否成功===========
1.怎样判断数据库中删除(整个表)表是否成功,用什么返回值,int   好象不行,


    2.删除成功之后,怎样在页面(C#中)判断数据库中是否存在该表(table1)

    select   name   from   sysobjects   where   name= 'table1 '   and   type= 'u '
 

      怎样得到这个select   查询的结果()




------解决方案--------------------
1.怎样判断数据库中删除(整个表)表是否成功,用什么返回值,int 好象不行,

---------
select * from sysobjects where xtype= 'U ' and name= 'aaa '
select @@rowcount

0:不存在
1: 存在

2.删除成功之后,怎样在页面(C#中)判断数据库中是否存在该表(table1)


-------------

if exists(select 1 from sysobjects where xtype= 'U ' and name= 'aa ')
begin


end

------解决方案--------------------
if object_id(name) is null
begin
--delete succeed
--not exists table1
end
else
begin
--delete failed
--exists table1
end
------解决方案--------------------
怎样判断数据库中删除(整个表)表是否成功?删除表的的DDL语法,要么成功,要么报错,报错了肯定是没成功了,这个跟本不用接返回值


在页面(C#中)判断数据库中是否存在该表

SqlCommand cmd = new SqlCommand( "select * from sysobjects where xtype= 'U ' and name= ' "+ 表名 + " ',cnn)

SqlDataReader dr = cmd.ExecuteReader()

if (dr.Read())
{
//如能进来,表肯定还在没有删除
}