locked
I want to insert XML Data into MySql Database RRS feed

  • Question

  • Hi All,
    I want to insert XML data into MySqlDatabase through C# , Do i require to need any change in it , because I will be getting XMl files and I have to save them into MySQL Database , Please suggest if any needful change is required here

           XmlDocument doc =new XmlDocument();
                // file to be get load
                doc.Load(@"C:\Users\Administrator\Desktop\books.xml");
                string data =doc.LoadXml;

                try{

                  //      This is the connection string to assigned the database file address path 
                    string str1 = @"server=test\sql2008;database=PRACTICE;uid=**;password=****;";

                    //    This is  MySqlConnection here i have created the object and pass my connection string.
                    MySqlConnection con = new MySqlConnection(str1);
                    con.open();

                    //    This is command class which will handle the query and connection object
                    MySqlCommand cmd = new MySqlCommand("storedProcedure Name",con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@defaultValue",defaultValue);
                   

                    cmd.ExecuteNonQuery(); 
                    con.Close();

                }
                catch (Exception ex)
                {
                    throw ex;

                }
    Saturday, May 16, 2015 8:58 AM

Answers

  • hello, here you have a tutorial on how to insert data from xml to a db, change references from sql to mysql.

    i don't know if mySql has a sqlBulkcopy option.. like here

    hope it helps..

    where is defaultValue declared ?

    • Marked as answer by John(Daniel) Saturday, May 16, 2015 9:20 AM
    Saturday, May 16, 2015 9:18 AM