Exemple #1
0
        /// <summary>
        /// 得到通用的主键
        /// </summary>
        /// <param name="TableName">表名</param>
        /// <param name="KeyFileid">主键ID</param>
        /// <param name="cmd">DbCommand</param>
        /// <returns>最大ID</returns>
        public static int GetMaxID(string TableName, string KeyFileid, OleDbCommand cmd)
        {
            Debug.Assert(!string.IsNullOrEmpty(TableName), "表 " + TableName + " 不存在!");
            Debug.Assert(!string.IsNullOrEmpty(KeyFileid), "主键ID为空!");
            Debug.Assert(cmd != null, "DbCommand为空!");
            string sql = string.Format("select max({0})  FROM {1}", KeyFileid, TableName);
            string ID  = DbHelperACE.GetSingle(sql, cmd).ToString();

            return(ID == "" ? 1 : int.Parse(ID) + 1);
        }
Exemple #2
0
        /// <summary>
        /// 获得最大ID
        /// </summary>
        /// <param name="FieldName">字段名</param>
        /// <param name="TableName">表名</param>
        /// <returns>最大ID</returns>
        public static int GetMaxID(string FieldName, string TableName)
        {
            Debug.Assert(!string.IsNullOrEmpty(FieldName), "字段 " + FieldName + " 不存在!");
            Debug.Assert(!string.IsNullOrEmpty(TableName), "表 " + TableName + " 不存在!");
            string strsql = "select max(" + FieldName + ")+1 from " + TableName;
            object obj    = DbHelperACE.GetSingle(strsql);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(int.Parse(obj.ToString()));
            }
        }
Exemple #3
0
        /// <summary>
        /// 检查查询结果是否存在
        /// </summary>
        /// <param name="strSql">sql语句</param>
        /// <returns>返回是否存在结果</returns>
        public static bool Exists(string strSql)
        {
            Debug.Assert(!string.IsNullOrEmpty(strSql), "要执行的SQL为空!");
            object obj = DbHelperACE.GetSingle(strSql);
            int    cmdresult;

            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }