oracle - Executing OracleCommand in a loop c# -


i execute stored procedure c# application using oracle.manageddataaccess.client.oraclecommand add data tables csv file.

each line on csv file it's parentreference,parentinfo,childreference,childinfo

csv file

p1,c11

p1,c12

p1,c13

p2,c21

result : 2 lines in first table p1 , p2

the stored procedure verify if parent exist else add it, after insert child.

the problem is, when call proc application, inserts same parent many times. when call application many times same data (line line) ok.

i have tried transaction, open , close connection each stored procedure call , still have same problem.

public class linedata {     public string parentreference {get;set;}     public string reference {get;set;}      internal bool savetodatabase(oracleconnection connection)     {         try         {             using (var command = connection.createcommand())             {                 oracletransaction trans = connection.begintransaction();                 command.transaction = trans;                  command.commandtext = "insert_data_from_line";                 command.commandtype = system.data.commandtype.storedprocedure;                  command.parameters.add("parentref", oracledbtype.varchar2, parentreference, system.data.parameterdirection.input);                 command.parameters.add("childref", oracledbtype.varchar2, reference, system.data.parameterdirection.input);                 // other parameters data                 var ret = command.executenonquery();                 trans.commit();             }             return true;         }         catch (exception ex)         {             return false;         }     } }   public class filedata {      internal list<linedata> initfromcsvfile(string filepath)     {         list<linedata> list = new list<linedata>();         var lines = file.readalllines(filepath);         foreach(var line in lines)         {             var infos = line.split(',');             list.add(new linedata(){parentreference = infos[0], reference = infos[1]});         }         return list;     }      public void saveall(string filepath)     {         var data = initfromcsvfile(fielpath);         oracleconnection connection = new oracleconnection(constr);         connection.open();         foreach (var item in data)         {             item.savetodatabase(connection);         }         connection.close();         connection.dispose();     } }  class program {     static void main(string[] args)     {         filedata filedata = new filedata();         filedata.saveall("c:\\data.csv");     } } 

is there way correct this?

ps : tried put minimum code.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -