/// <summary> /// 执行一存储过程返回数据表 返回多个值 /// <param name="procName">存储过程名称</param> /// <param name="ht">Hashtable</param> /// <param name="rs">Hashtable</param> public DataTable GetDataTableProcReturn(string procName, Hashtable ht, ref Hashtable rs) { try { dbCommand = this.GetInstance().GetStoredProcCommand(procName); DbCommon.AddMoreParameter(db, dbCommand, ht); DataTable dt = DbReader.ReaderToDataTable(db.ExecuteReader(dbCommand)); rs = new Hashtable(); foreach (string key in ht.Keys) { if (key.StartsWith("OUT_")) { string tmp = key.Remove(0, 4); object val = db.GetParameterValue(dbCommand, ":" + tmp); rs[key] = val; } } return(dt); } catch (Exception e) { DbLog.WriteException(e); return(null); } }
public void ParametersAreAddedWhenUsingDbCommand() { OracleDatabase db = (OracleDatabase)DatabaseFactory.CreateDatabase("OracleTest"); DbCommand dbCmd = db.GetStoredProcCommand("AddCountryInvalidSP"); db.AddInParameter(dbCmd, "Param", DbType.Int32, 10); db.AddInParameter(dbCmd, "Param", DbType.Int32, 20); Assert.AreEqual(2, dbCmd.Parameters.Count); Assert.AreEqual(10, (int)db.GetParameterValue(dbCmd, "Param")); DbCommand dbCmd1 = db.GetSqlStringCommand("select * from InvalidType"); Guid guid = Guid.NewGuid(); db.AddInParameter(dbCmd1, "Param1", DbType.Guid, guid); Assert.AreEqual(guid, (Guid)db.GetParameterValue(dbCmd1, "Param1")); DbCommand dbCmd2 = db.GetSqlStringCommand("select * from InvalidType"); db.AddInParameter(dbCmd2, "Param3", DbType.Boolean, true); Assert.AreEqual(true, (bool)db.GetParameterValue(dbCmd2, "Param3")); }
public void GuidIsPassedAsPrameterAndReturnedAsOutput() { OracleDatabase db = (OracleDatabase)DatabaseFactory.CreateDatabase("OracleTest"); Guid myVal = new Guid("33333333333333333333333333444444"); string spName = "sp_GUIDTEST"; DbCommand dbCommand = db.GetStoredProcCommand(spName); db.AddInParameter(dbCommand, "vGuidInput", DbType.Guid); db.SetParameterValue(dbCommand, "vGuidInput", myVal); db.AddParameter(dbCommand, "vGuidOutput", DbType.Guid, ParameterDirection.Output, "", DataRowVersion.Current, null); db.ExecuteNonQuery(dbCommand); Guid outputVal = (Guid)db.GetParameterValue(dbCommand, "vGuidOutput"); Assert.IsTrue(myVal.Equals(outputVal)); }