예제 #1
0
파일: DbInfo.cs 프로젝트: yalunwang/shbus
        /// <summary>
        /// 根据链接构建实例
        /// </summary>
        private DbInfo()
        {
            DatabaseProviderFactory factory = new DatabaseProviderFactory();
            db = factory.Create("DBConnStr");
            ExecuteResult = new DbResult();

            Procdbcomm = db.DbProviderFactory.CreateCommand();
            listDbParameter = new List<DbParameter>();
        }
예제 #2
0
        /// <summary>
        /// 执行查询操作
        /// </summary>
        /// <param name="command">这个参数没什么用</param>
        /// <returns></returns>
        public int ExecuteNonQuery(DbCommand command)
        {
            int ret = 0;
            ExecuteResult = new DbResult();
            try
            {
                if (Procdbcomm.CommandType == CommandType.StoredProcedure)
                    db.AddParameter(Procdbcomm, "ReturnValue", DbType.Int32, ParameterDirection.ReturnValue, "", DataRowVersion.Default, 0);

                //执行查询
                ret = db.ExecuteNonQuery(Procdbcomm);
                for (int i = 0; i < Procdbcomm.Parameters.Count; i++)
                {
                    var item = Procdbcomm.Parameters[i];
                    ///输出类型的参数
                    if (item != null)
                    {
                        if (item.Direction == ParameterDirection.InputOutput
                        || item.Direction == ParameterDirection.Output)
                        {
                            object paramValue = item.Value;// db.GetParameterValue(Procdbcomm, item.ParameterName);
                            if (item.ParameterName.ToLower() == "@ret")
                            {
                                if (paramValue is long)
                                    ExecuteResult.LongRet = (long)paramValue;
                                if (paramValue is int)
                                    ExecuteResult.IntRet = (int)paramValue;
                            }
                            if (item.ParameterName.ToLower() == "@stroutput")
                            {
                                ExecuteResult.StrOutput = paramValue.ToString();
                            }
                            ExecuteResult.OutValues.Add(item.ParameterName, paramValue);
                        }
                        if (item.Direction == ParameterDirection.ReturnValue)
                        {
                            ExecuteResult.ReturnValue = (int)item.Value;
                        }
                    }
                }
            }
            finally
            {
                Clear();
            }
            return ret;
        }