/// <summary> /// 核查表是否存在 /// </summary> /// <param name="tableName">表名</param> /// <returns></returns> public bool ExistTable(string tableName) { var sqlHelper = new SqlHelper.SqlHelper(); string cmdText = string.Format("SELECT Count(*) FROM SYSOBJECTS WHERE ID = OBJECT_ID('{0}') AND OBJECTPROPERTY(ID, 'IsUserTable') = 1", tableName); return(sqlHelper.ExecuteScalar(cmdText).ToInt() > 0 ? true : false); }
/// <summary> /// 核查字段是否存在 /// </summary> /// <param name="tableName">表名</param> /// <param name="fieldName">字段名</param> /// <returns></returns> public bool ExistField(string tableName, string fieldName) { var sqlHelper = new SqlHelper.SqlHelper(); //查询字段 string cmdTextField = string.Format("select Count(*) from syscolumns where id=object_id('{0}') and name='{1}'", tableName, fieldName); return(sqlHelper.ExecuteScalar(cmdTextField).ToInt() > 0 ? true : false); }