Example #1
0
        /// <summary>
        /// 根据数据库的序列查找最大ID
        /// </summary>
        /// <param name="tsName">序列名</param>
        /// <returns></returns>
        public static long GenerateSEQIdentity(String tsName)
        {
            OracleCommand loOraComm = DBA.GetOraCommand();

            try
            {
                if (tsName == "")
                {
                    return(-1);
                }
                loOraComm.CommandText = "GenerateIdentity2";
                loOraComm.CommandType = CommandType.StoredProcedure;
                OracleParameter parameter = loOraComm.CreateParameter();
                parameter.ParameterName = "PropertyName";
                parameter.OracleType    = OracleType.NVarChar;
                parameter.Size          = 50;
                parameter.SourceColumn  = "Name";
                parameter.Value         = tsName;
                loOraComm.Parameters.Add(parameter);
                parameter = loOraComm.CreateParameter();
                parameter.ParameterName = "NewIdentityValue";
                parameter.OracleType    = OracleType.Number;
                parameter.Direction     = ParameterDirection.Output;
                loOraComm.Parameters.Add(parameter);
                loOraComm.ExecuteNonQuery();

                if (Convert.ToInt64(parameter.Value) == 0)
                {
                    throw new Exception("此表没有相应的序列");
                }
                else
                {
                    return(Convert.ToInt64(parameter.Value));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("根据序列取表主键出错!", ex);
            }
            finally
            {
                DBA.RealseOraCommand(loOraComm);
            }
        }