本文介绍了如何将对象传递给oracle存储过程(odp)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将一个对象传递给存储过程以插入数据..
我尝试过此编码
I need to pass an object to stored procedure for inserting the data..
I tried this coding
button_click()
{
insert_pro insobj = new insert_pro();
insobj.ID = Convert.ToInt16(textBox1.Text);
insobj.Name = textBox2.Text;
insobj.Gender =Convert.ToChar(textBox3.Text);
OracleConnection conn = new OracleConnection("Data Source=r2a;User ID=testv55;Password=testv55;");
conn.Open();
OracleCommand cmd = new OracleCommand("smp_ins", conn);
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter emp_obj = new OracleParameter();
emp_obj.OracleDbType = OracleDbType.Object;
emp_obj.Direction = ParameterDirection.Input;
emp_obj.UdtTypeName = "EMP_TYP";
emp_obj.Value = insobj;
cmd.Parameters.Add(emp_obj);
cmd.ExecuteNonQuery();
con.close();
}
insert_pro类别:
insert_pro class:
namespace test_form
{
public class insert_pro:IOracleCustomType
{
[OracleObjectMappingAttribute("Id")]
public virtual int ID { get; set; }
[OracleObjectMappingAttribute("Name")]
public virtual string Name { get; set; }
[OracleObjectMappingAttribute("Gender")]
public virtual char Gender { get; set; }
public virtual void FromCustomObject(OracleConnection conn, IntPtr objUdt)
{
OracleUdt.SetValue(conn, objUdt, "Id", this.ID);
OracleUdt.SetValue(conn, objUdt, "Name", this.Name);
OracleUdt.SetValue(conn, objUdt, "Gender", this.Gender);
}
public virtual void ToCustomObject(OracleConnection conn, IntPtr objUdt)
{
this.ID = ((int)(OracleUdt.GetValue(conn, objUdt, "Id")));
this.Name = ((string)(OracleUdt.GetValue(conn, objUdt, "Name")));
this.Gender = ((char)(OracleUdt.GetValue(conn, objUdt, "Gender")));
}
}
}
错误消息是未指定"test_form.insert_pro"的自定义类型映射或无效
error message is Custom type mapping for ''test_form.insert_pro'' is not specified or is invalid
推荐答案
[OracleCustomTypeMappingAttribute("TESTV55.SMP_EMP_TYPE")]
public class ins_Factory : IOracleCustomTypeFactory
{
public virtual IOracleCustomType CreateObject()
{
insert_pro obj = new insert_pro();
return obj;
}
}
这篇关于如何将对象传递给oracle存储过程(odp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!