各位高手:
    我写了这样一段代码:
        private static bool DeleteTable(SqlCeConnection cn, string TableName)
        {
            string strSQL = @"DROP TABLE IF EXISTS " + TableName ;
            try
            {
                if (cn.State != ConnectionState.Open)
                {
                    cn.Open();
                }
                SqlCeCommand SqlCeCmd = new SqlCeCommand(strSQL, cn);                SqlCeCmd.ExecuteNonQuery();
                return true;
            }
            catch (SqlCeException ex)
            {                MessageBox.Show( ex.Message);
                return false;
            }
        }
报错:Token line number=1 ,token line offset=12,Token in error=IF
调用语句是DeleteTable(cn, "xzqy")
我跟进去了,看到连接都没问题,字符串是DROP TABLE IF EXISTS xx(我的表名),但是还是抛出异常希望各位大侠赐教,不生感激阿!!

解决方案 »

  1.   

    IF EXISTS xx
       DROP TABLE 
      

  2.   

    if object_id('tbname') is not null
       drop table tbname
    go
      

  3.   

    if object_id('tbname','u') is not null
      drop table tbname
    go
      

  4.   

    if object_id('dbname..tbname') is not null
       drop table tbname
    go
      

  5.   

    if exists(select 1 from sysobjects where name='tbname' and xtype='u')
    drop table tbname
    go或这样
      

  6.   

    [Quote=引用 5 楼 htl258 的回复:]
    首先谢过!
    我想问一下,可是这个表如果是空的呢?也或者没有,select不久不成功了么?
      

  7.   

    if object_id('dbname..tbname') is not null
       drop table tbname
    go
      

  8.   


    就是判断表是否为空 为空的话还DROP什么?
      

  9.   

    drop table if exists address_book;这句SQL语句是什么意思
     悬赏分:10 - 解决时间:2009-7-17 09:36 
    我备份的SQL语句中有这么一行,不知道是什么意思? 提问者: QQ41678438 - 二级最佳答案如果数据库中存在address_book表,就把它从数据库中drop掉。
    备份sql中一般都有这样的语句,如果是数据库中有这个表,先drop掉,然后create表,然后再进行数据插入。 '网上竟然也有“drop table if exists **”这样的写法,不知道是什么数据库中的语句??'
      

  10.   


    就是嘛!不是有个 exists 么!!
      

  11.   


    我是不想让这个表存在啊。因为下面用到PULL,如果表存在它就失败了
      

  12.   

    也就是IF EXISTS如果条件为真,那个表就会被DROP掉,条件为否,就不会执行DROP的动作。
      

  13.   

     if exists(select object_id('tt')) 
    drop table tt
      

  14.   

    谢谢各位!我终于明白了呵呵,因为太菜,开始没明白里面的select是系统表。非常感谢大家!谢谢
      

  15.   

    Oracle  MySQL 唉..........
      

  16.   

    if exists(select object_id('tt'))  
    drop table tt