我正在尝试在我的c#应用程序中映射一个简单的Oracle UDT。当我尝试从DataReader
中提取数据时,会抛出以下异常:
'dataSource ='DB'的自定义类型映射schemaName ='C ## LAZAR' typeName ='MATICNIBROJ_T''未指定或无效
Oracle UDT 是:
create or replace
TYPE "MATICNIBROJ_T" AS OBJECT (
MaticniBroj NUMBER(13)
)
INSTANTIABLE NOT FINAL
用于映射的自定义类:
[OracleCustomTypeMapping("C##LAZAR.MATICNIBROJ_T")]
public class MaticniBrojT : IOracleCustomType
{
[OracleObjectMappingAttribute("MaticniBroj")]
public virtual int MaticniBroj { get; set; }
//c# custom type --> Oracle UDT
public virtual void FromCustomObject(OracleConnection conn, IntPtr obj)
{
OracleUdt.SetValue(conn, obj, "MaticniBroj", this.MaticniBroj);
}
//Oracle UDT --> c# custom type
public virtual void ToCustomObject(OracleConnection conn, IntPtr obj)
{
this.MaticniBroj = ((int)(OracleUdt.GetValue(conn, obj, "MaticniBroj")));
}
}
数据库通信:
string upit = @"SELECT PIB, NAZIV, RACUN, FAX, TELEFON, ADRESA, EMAIL,
MATICNIBR FROM KOMITENT_VW k WHERE UPPER(NAZIV) LIKE '%" + naziv.ToUpper() + "%'";
conn = napraviKonekciju();
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = upit;
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("PIB");
dt.Columns.Add("NAZIV");
dt.Columns.Add("RACUN");
dt.Columns.Add("FAX");
dt.Columns.Add("TELEFON");
dt.Columns.Add("ADRESA");
dt.Columns.Add("EMAIL");
dt.Columns.Add("MATICNIBR");
ds.Tables.Add(dt);
while(dr.Read())
{
DataRow red = dt.NewRow();
red["PIB"] = dr.GetInt32(0);
red["NAZIV"] = dr.GetString(1);
red["RACUN"] = dr.GetString(2);
red["FAX"] = dr.GetString(3);
red["TELEFON"] = dr.GetString(4);
red["ADRESA"] = dr.GetString(5);
red["EMAIL"] = dr.GetString(6);
//----next line throws an exception
MaticniBrojT mBroj = (MaticniBrojT)dr.GetValue(7);
red["MATICNIBR"] = Convert.ToInt64(mBroj.MaticniBroj);
}
return ds;
}
catch (Exception ex)
{
return null;
}
finally
{
conn.Close();
conn.Dispose();
conn = null;
}
大多数代码由用户LSA提供。但错误是我的错误。 有人可以澄清我哪里出错吗?
答案 0 :(得分:1)
在您的错误消息中,它显示了' dataSource =' DB'的自定义类型映射。 schemaName = ' C ## USER' typeName =' MATICNIBROJ_T''未指定或无效
在您的自定义类型映射中,它显示[OracleCustomTypeMapping(" C ## LAZAR .MATICNIBROJ_T")]
尝试调整它并再次运行代码。