usingMySql.Data.MySqlClient;usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Xml.Linq;namespacexml{classProgram {Static voidMain (string[] args) { //XML Import Database//Read XMLXDocument Xdoc = Xdocument.load (@"C:\Users\Administrator\Desktop\xml\stu.xml"); //root nodeXElement root =Xdoc. Root; //Traverse all child nodes under the root node foreach(varIteminchRoot. Elements ()) {stringsql ="INSERT into T_student (name,age,gender) VALUES (@name, @age, @gender);"; Mysqlparameter[] PS= { NewMysqlparameter ("@name", item. Element ("Stuname"). Value),NewMysqlparameter ("@age", item. Element ("Stuage"). Value),NewMysqlparameter ("@gender", item. Element ("Stugender"). Value)}; Mysqlhelper.executenonquery (SQL,PS); } Console.WriteLine ("data import Successful!"); Console.readkey (); } }}
C # XML Import Database