c# - mysql stored procedure bulk insert -


i have stored procedure looks that:

insertitem: insert (in itemid int, name text); 

is there way execute bulk of it? instead of executing that:

using (mysqlconnection connection = new mysqlconnection(_connectionstring)) {     connection.open();     foreach (item item in getitems())     {         using (mysqlcommand command = new mysqlcommand("insertitem", connection))         {             command.commandtype = commandtype.storedprocedure;             command.parameters.addwithvalue("@itemid", item.itemid);             command.parameters.addwithvalue("@name", item.name);             command.executenonquery();         }     } } 

i'm trying achieve code looking without successing:

using (mysqlconnection connection = new mysqlconnection(_connectionstring)) {     connection.open();     using (mysqlcommandbulk command = new mysqlcommand("insertitem", connection))     {         command.commandtype = commandtype.storedprocedure;         (item item in getitems())         {             mysqlcommandbulkitem bulkitem = new mysqlcommandbulkitem();             bulkitem["itemid"] = item.itemid;             bulkitem["name"] = item.name;             command.bulkitems.add(bulkitem);         }         command.execute();     } } 

my point command send of data @ once, , not send each query alone.
ideas?

the oracle connector dotnet framework allows use of arrays in place of scalars on parameters. mysql connector doesn't.

there 2 ways accelerate bulk loads in mysql.

one of them applies innodb tables doesn't myisam tables. start transaction. then, after every few hundred rows, commit , start one. commit table inserts in bunches, faster autocommiting them individually.

the other use mysql's load data infile command slurp data file , bulk-insert database. fast, have diligent formatting file correctly.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -