Private ObjectBlubckmysql (list<xiaoyao_blogs_picturemodel> List,stringConnect) { varSqllist = list. Select (item =string. Format (@"INSERT INTO Xiaoyao_blogs_picture (classifyname,pictureurl,pictureintroduce,username,addtime) VALUES (' {0} ', ' {1 } ', ' {2} ', ' {3} ', ' {4} ')", Item.classifyname, Item.pictureurl, Item.pictureintroduce, Item.username, Item.addtime). ToList (); using(varconn =Newmysqlconnection (Connect)) {Conn. Open (); Mysqlcommand cmd=NewMysqlcommand (); Cmd. Connection=Conn; Mysqltransaction TX=Conn. BeginTransaction (); Cmd. Transaction=TX; Try { for(intn =0; N < sqllist. Count; n++) { stringstrSQL =Sqllist[n]. ToString (); if(strSQL. Trim (). Length >1) {Cmd.commandtext=strSQL; varA=cmd. ExecuteNonQuery (); } //start things every 500 times if(N >0&& (n% -==0|| n = = sqllist. Count-1) ) {tx.commit (); TX=Conn. BeginTransaction (); } } } Catch(System.Data.SqlClient.SqlException E) {tx. Rollback (); Throw NewException (e.message); } } return NULL; }
MySQL Bulk upload data