I am trying to map a simple Oracle UDT in my c# application. When I try to extract data from DataReader, it throws the following exception:
Custom class used for mapping:
DB communication:
Any suggestions?
Custom type mapping for 'dataSource='DB' schemaName='C##USER' typeName='MATICNIBROJ_T'' is not specified or is invalid
My Oracle UDT is:
C#:
create or replace
TYPE "MATICNIBROJ_T" AS OBJECT (
MaticniBroj NUMBER(13)
)
INSTANTIABLE NOT FINAL
Custom class used for mapping:
C#:
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")));
}
}
DB communication:
C#:
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;
}
Any suggestions?