//检查表中是否存在指定的列 public static bool CheckColumnExist(string dbname, string tableName, string colName) { Database db = DbFunction.GetDB(dbname); string sql = string.Empty; if (db.DBType == DataBaseType.ORA) { sql = "SELECT COUNT(1) as EXISTFLAG FROM USER_TAB_COLS WHERE COLUMN_NAME=UPPER('" + colName + "') AND TABLE_NAME=UPPER('" + tableName + "')"; } else { sql = "SELECT COUNT(1) from syscolumns c,sysobjects o where o.id=c.id and Upper(o.name) = Upper('" + tableName + "') and o.type = 'U' and Upper(c.name) = Upper('" + colName + "')"; } int count = Convert.ToInt32(DbFunction.ExecuteScalar(dbname, sql)); if (count == 0) { return(false); } else { return(true); } }
//判断表在数据库中是否存在 public static bool CheckTableExist(string dbname, string tableName) { Database db = DbFunction.GetDB(dbname); string sql = string.Empty; if (db.DBType == DataBaseType.ORA) { sql = "SELECT COUNT(1) FROM USER_TABLES WHERE TABLE_NAME = UPPER('" + tableName + "')"; } else { sql = "SELECT COUNT(1) from sysobjects where Upper(name) = Upper('" + tableName + "') and type = 'U'"; } int count = Convert.ToInt32(DbFunction.ExecuteScalar(dbname, sql)); if (count == 0) { return(false); } else { return(true); } }