Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:48:03+00:00 2026-06-12T23:48:03+00:00

I need a fastest solution for transferring data from XML file to MySQL tables.

  • 0

I need a fastest solution for transferring data from XML file to MySQL tables.
I have XML file with multiple tables inside, like this:

<?xml version="1.0" standalone="yes"?>
<RawData xmlns="">
  <Table1>
    <ID_Table1>1</ID_Table1>
    <Name>Victor</Name>
  </Table1>
  <Table2>
    <ID_Table2>1</ID_Table2>
    <Quantity>10</Quantity>
  </Table2>
</RawData>

and within VS2010, i have DataSource with DataTables and TableAdapters from MySql db for Table1 and Table2.
My goal was to read XML file and pass its data directly to these DataTables with this:

myDSDataSet eDS = (myDSDataSet)this.FindResource("myDS"); // Declared in XAML

OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "XML Files|*.xml";
dlg.Title = "Select a XML File";

Nullable<bool> result = dlg.ShowDialog();

if (result == true)
{                  
 mt1TableAdapter mt1_TA = new mt1TableAdapter();
 mt2TableAdapter mt2_TA = new mt2TableAdapter();
 manager = new TableAdapterManager();       

 xmlDS = new DataSet();
 dt = null;

 try
 {                     
   xmlDS.ReadXml(dlg.FileName,XmlReadMode.InferTypedSchema);

   for (int i = 0; i < xmlDS.Tables.Count; i++)
   {                          
     dt = xmlDS.Tables[i].Copy();

     eDS.Tables[eDS.Tables.IndexOf(xmlDS.Tables[i].TableName)].Merge(dt);                           
   }

   mt1_TA.Update(eDS.mt1);
   mt2_TA.Update(eDS.mt2);

   MessageBox.Show("Loading complete.");
 }
 catch (Exception error)
 {
    MessageBox.Show("ERROR: " + error.Message);
 }              
}

But after executing this code i got 2 big problems:
1. If data types differ i get exception (in DataSource field is DateTime, XML field is read as string)
2. Calling TableAdapter.Update() takes a long time to save data to db (15k rows takes 10-15mins)

So… my question is, Can someone please help me solve these two problems or give me some direction as to what is the fastest and best method for saving XML data to mysql.

Note:
– I’m using VS2010 and MySQL 5.1.
– XML file needs to be loaded from external source.
– XML has its xmlns but its omitted here for simplicity.
– I tried upgrading MySQL to 5.6 and using LOAD XML but i cant use this command within stored procedure.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:48:04+00:00Added an answer on June 12, 2026 at 11:48 pm

    Ok, I’ve resolved this problem. Posting here just in case someone else comes across this problem. Following solution uses predefined schema’s for table structure and BackGroundWorker for data processing.
    Idea was to input newly read data into MySQL tables using StringBuilder (fastest way to generate huge strings). StringBuilder variable takes all sql expressions and executes in single “go” on DB (reduces time of processing greatly!).

    StringBuilder sqlCommand = new StringBuilder();
    
    DataSet xmlDS = new DataSet();
    
    try
    {
       xmlDS.ReadXmlSchema(shemaPath); 
       xmlDS.ReadXml(dlg.FileName, XmlReadMode.ReadSchema);           
    
       sqlCommand.Clear();
       sqlCommand.Append("START TRANSACTION;");  
    
        for (int i = xmlDS.Tables.Count-1; i >= 0; i--)
        {
           if (xmlDS.Tables[i].Rows.Count > 0) 
              sqlCommand.Append("DELETE FROM " + xmlDS.Tables[i].TableName + "; ");
        }   
    
        int brojacDataTable = 0;             
    
        foreach (DataTable dataTable in xmlDS.Tables) 
        {
            brojacDataTable++;
            if (dataTable.Rows.Count > 0)
            {    
              sqlCommand.Append(" INSERT INTO " + dataTable.TableName + " VALUES");
    
              int brojacDataRows = 0;
              foreach (DataRow dataRow in dataTable.Rows)
              {
                 brojacDataRows++;
                 sqlCommand.Append("(");
    
                 for (int i = 0; i < dataRow.ItemArray.Length; i++)
                 {
                    if (!System.DBNull.Value.Equals(dataRow.ItemArray[i]))
                    {
                      if (dataRow.ItemArray[i] is System.DateTime) sqlCommand.Append("'" +((DateTime)dataRow.ItemArray[i]).ToString("yyyy-MM-dd") + "'");
                      else sqlCommand.Append("'" + dataRow.ItemArray[i].ToString() + "'");
                    }
                    else sqlCommand.Append("null");
    
                   if (i < dataRow.ItemArray.Length - 1) sqlCommand.Append(",");
                 }
    
                if (brojacDataRows < dataTable.Rows.Count) sqlCommand.Append("),");
                else sqlCommand.Append(");");
               }
            }
         }
    
      sqlCommand.Append("COMMIT;");
    

    In the end, after some testing, total time for uploading roughly 30 tables with 200.000+ records was less than 20seconds 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
I have enumeration like this: public enum Configuration { XML(1), XSLT(10), TXT(100), HTML(2), DB(20);
In my code, I have a situation where I need to copy data from
I have some data like this: 1 2 3 4 5 9 2 6
I need fastest way to convert files from latin1 to utf-8 in python. The
I need a fastest way to find any point inside triangle(not edges) in 2D.
Need help with a query that I wrote: I have three tables Company id
Say I have a string that looks like this: str = The &yquick &cbrown
I'm using PHP and MySQL. I need to do a query: DELETE FROM db1.players
I have this Problem and solving it is not the problem, more like what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.