/// <summary> /// 根据链接构建实例 /// </summary> private DbInfo() { DatabaseProviderFactory factory = new DatabaseProviderFactory(); db = factory.Create("DBConnStr"); ExecuteResult = new DbResult(); Procdbcomm = db.DbProviderFactory.CreateCommand(); listDbParameter = new List<DbParameter>(); }
/// <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; }