C# &引用;值不在预期范围内;将UDT传递给存储过程时
下面是我在Oracle中映射到UDT的类(非常简单):C# &引用;值不在预期范围内;将UDT传递给存储过程时,c#,oracle,stored-procedures,user-defined-types,odp.net-unmanaged,C#,Oracle,Stored Procedures,User Defined Types,Odp.net Unmanaged,下面是我在Oracle中映射到UDT的类(非常简单): [OracleCustomTypeMapping("PORTAL_OPS.SHAPEUDT")] public class Shape : IOracleCustomType, IOracleCustomTypeFactory { [OracleObjectMapping("SIDES")] public Int32 Sides { get; set; } public string UdtTypeName { get
[OracleCustomTypeMapping("PORTAL_OPS.SHAPEUDT")]
public class Shape : IOracleCustomType, IOracleCustomTypeFactory
{
[OracleObjectMapping("SIDES")]
public Int32 Sides { get; set; }
public string UdtTypeName
{
get
{
Attribute attr = Attribute.GetCustomAttribute(this.GetType()
, typeof(OracleCustomTypeMappingAttribute));
return (attr != null) ?
((OracleCustomTypeMappingAttribute)attr).UdtTypeName
:
String.Empty;
}
}
public void FromCustomObject(OracleConnection con, IntPtr pUdt)
{
OracleUdt.SetValue(con, pUdt, "SIDES", Sides);
}
public void ToCustomObject(OracleConnection con, IntPtr pUdt)
{
Sides = (int)OracleUdt.GetValue(con, pUdt,"SIDES");
}
public IOracleCustomType CreateObject()
{
return new Shape();
}
if (Command.Connection.State == ConnectionState.Closed)
{
Command.Connection.Open();
}
// setting up the parameter
OracleParameter param = new OracleParameter();
param.Direction = ParameterDirection.Input;
param.UdtTypeName = udt.UdtTypeName;
param.DbType = DbType.Object;
param.OracleDbType = OracleDbType.Object;
param.Value = udt;
Command.CommandText = "PORTAL_OPS.PROC_CREATE_SHAPE";
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add(param);
Command.ExecuteNonQuery();
Shape shape = new Shape();
shape.sides = 4;
//invoking the stored procedure call (see code above)
}
调用存储过程:
[OracleCustomTypeMapping("PORTAL_OPS.SHAPEUDT")]
public class Shape : IOracleCustomType, IOracleCustomTypeFactory
{
[OracleObjectMapping("SIDES")]
public Int32 Sides { get; set; }
public string UdtTypeName
{
get
{
Attribute attr = Attribute.GetCustomAttribute(this.GetType()
, typeof(OracleCustomTypeMappingAttribute));
return (attr != null) ?
((OracleCustomTypeMappingAttribute)attr).UdtTypeName
:
String.Empty;
}
}
public void FromCustomObject(OracleConnection con, IntPtr pUdt)
{
OracleUdt.SetValue(con, pUdt, "SIDES", Sides);
}
public void ToCustomObject(OracleConnection con, IntPtr pUdt)
{
Sides = (int)OracleUdt.GetValue(con, pUdt,"SIDES");
}
public IOracleCustomType CreateObject()
{
return new Shape();
}
if (Command.Connection.State == ConnectionState.Closed)
{
Command.Connection.Open();
}
// setting up the parameter
OracleParameter param = new OracleParameter();
param.Direction = ParameterDirection.Input;
param.UdtTypeName = udt.UdtTypeName;
param.DbType = DbType.Object;
param.OracleDbType = OracleDbType.Object;
param.Value = udt;
Command.CommandText = "PORTAL_OPS.PROC_CREATE_SHAPE";
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add(param);
Command.ExecuteNonQuery();
Shape shape = new Shape();
shape.sides = 4;
//invoking the stored procedure call (see code above)
实例化:
[OracleCustomTypeMapping("PORTAL_OPS.SHAPEUDT")]
public class Shape : IOracleCustomType, IOracleCustomTypeFactory
{
[OracleObjectMapping("SIDES")]
public Int32 Sides { get; set; }
public string UdtTypeName
{
get
{
Attribute attr = Attribute.GetCustomAttribute(this.GetType()
, typeof(OracleCustomTypeMappingAttribute));
return (attr != null) ?
((OracleCustomTypeMappingAttribute)attr).UdtTypeName
:
String.Empty;
}
}
public void FromCustomObject(OracleConnection con, IntPtr pUdt)
{
OracleUdt.SetValue(con, pUdt, "SIDES", Sides);
}
public void ToCustomObject(OracleConnection con, IntPtr pUdt)
{
Sides = (int)OracleUdt.GetValue(con, pUdt,"SIDES");
}
public IOracleCustomType CreateObject()
{
return new Shape();
}
if (Command.Connection.State == ConnectionState.Closed)
{
Command.Connection.Open();
}
// setting up the parameter
OracleParameter param = new OracleParameter();
param.Direction = ParameterDirection.Input;
param.UdtTypeName = udt.UdtTypeName;
param.DbType = DbType.Object;
param.OracleDbType = OracleDbType.Object;
param.Value = udt;
Command.CommandText = "PORTAL_OPS.PROC_CREATE_SHAPE";
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add(param);
Command.ExecuteNonQuery();
Shape shape = new Shape();
shape.sides = 4;
//invoking the stored procedure call (see code above)
我不明白为什么我一直得到“值不在预期范围内”。整个周末都在看这个…运气不好。非常感谢您的帮助。您能为您传递的值添加一个示例吗?@Marcourelio Fernandezreyes…addedd Oracle自定义类型中边值的数据类型是什么?我以前在Oracle到.NET的映射中遇到过问题,Oracle端是数字(无精度)-我发现decimal在这个实例中工作得相当好。@DominicCotton在对象中,我有这样一个:sides NUMBER(1,0)您能为您传递的值添加一个示例吗?@Marcourelio Fernandezreyes…addedd Oracle自定义类型中边值的数据类型是什么?我以前在Oracle到.NET的映射中遇到过问题,Oracle端是数字(无精度)-我发现decimal在这个实例中工作得相当好。@DominicCotton在对象中,我有这样一个:sides NUMBER(1,0)