I want to insert multiple rows through a stored procedure calling it from C#.NET. I am using OracleDataAccess.dll unmanaged .net driver provided by Oracle for .NET and using VS 2015. My program is a console program that will read excel files (one by one) looking a specific worksheets in the excel and insert the data from the worksheet into a table in oracle.
I have researched and found people say that it can be done through XML, UDT and OracleBulkCopy but the code I have found does not work. I tried testing it by running it as an xml line of code. The screen dump of this error is provided at the very end.
I am looking for a solution on how to pass it from C# to Oracle to achieve the outcome of inserting these records in the Oracle table. I would appreciate if you can help me figure this out on the Oracle and C#.NET.
C#.NET side code below:
public class DSelect
{
public string Installation { get; set; }
public int Account { get; set; }
public int BusinessNumber { get; set; }
public long Sysd { get; set; }
public decimal LocX { get; set; }
public string Type { get; set; }
public string Wattage { get; set; }
public decimal ALen { get; set; }
public int LWatt { get; set; }
public string Tempr { get; set; }
public DateTime CreatedDate { get; set; }
}
List<DSelect> listDSelect = new List<DSelect>();
.... Reading an excel worksheet row in a loop and building my list. There can be between 500 to 1000 rows of data in the worksheet
var deSel= new DSelect();
deSel.Installation = "install1";
.................................
listDSelect.Add(deSel)
XmlSerializer serializer = new XmlSerializer(typeof(List<DSelect>));
var stringwriter = new System.IO.StringWriter();
serializer.Serialize(stringwriter, listDSelect);
Pass to stored procedure to insert into table in Oracle database 12c.
- I want to pass the entire list to the oracle stored procedure as a object.
- In the oracle stored procedure receive it and and insert it into a table.
Test code that fails in SQL Developer :
DECLARE
p_AdditionRequest varchar2(30000); -- CLOB;
t_xmlType SYS.XMLTYPE;
BEGIN
p_AdditionRequest:= '<?xml version="1.0" encoding="utf-16"?>
<ArrayOfDetailedSelection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DetailedSelection>
<Installation>645805</InstallationNumber>
<AccountNumber>33170019251</AccountNumber>
</DetailedSelection>
</ArrayOfDetailedSelection>';
--t_xmlType := sys.xmltype.createxml(p_AdditionRequest);
SELECT InstallationNumber, AccountNumber (
SELECT ExtractValue(column_value, '/DetailedSelection/InstallationNumber') InstallationNumber,
ExtractValue(column_value, '/DetailedSelection/AccountNumber') AccountNumber
FROM TABLE(XMLSequence(XMLTYPE(p_AdditionRequest).EXTRACT('/ArrayOfDetailedSelection/DetailedSelection')))
)
END;
/