SQL Insert Performance I am using a DataTable and the MySqlAdapater to insert around 100 000 rows with around 40 columns to a MySQL database.

I chose this way, because my program needs run on mono (unix / mac) where I could not establish a connection to my database via the System.Data.Sql package, but only via the .NET connector Mysql.Data.MySqlClient which has no SqlBulkCopy-method.

Additionally the amount of columns in my table is flexible, so I was looking for an easy way to iterate the columns. Thats why I used the way:


Parsing my data
Loading it into a DataTable Object
Create a MySQL table dynamically based on my DataTable Object
Use a MySqlDataAdapter to bulk insert the DataTable to the Database via its .Update()-method 


Right now, it takes around 3-4 minutes to insert 100 000 rows this way - which is subjectively slow (mac mini 2012, i7, 512 GB SSD, 16 GB ram)

Is there any way to speed this up with the Mysql.Data.MySqlClient ?

public static void Import(DataTable dt, string tableName, string conString)
        {
            using (MySqlConnection con = new MySqlConnection(conString))
            {
                con.Open();

                string createTableString = GetCreateTableSql(dt, tableName);
                MySqlCommand cmd = new MySqlCommand(createTableString, con);
                cmd.ExecuteNonQuery();

                using (MySqlCommand selectcmd = new MySqlCommand("SELECT * FROM " + dt.TableName, con))
                {
                    using (MySqlDataAdapter sda = new MySqlDataAdapter())
                    {
                        MySqlCommandBuilder builder = new MySqlCommandBuilder(sda);
                        sda.SelectCommand = selectcmd;

                        builder.GetUpdateCommand();

                        using (DataTable dttemp = new DataTable())
                        {
                            sda.Fill(dttemp);
                            // prevent duplicating data
                            if (dttemp.Rows.Count == 0)
                            {
                                dttemp.Merge(dt);
                                sda.Update(dttemp);
                            }
                            else 
                            {
                                Console.WriteLine("Data already present. Delete manually");
                            }

                        }
                    }
                }
            }
        }
Some quick remarks:


Naming is important. I don't consider dt, conString, con, etc. proper names since they don't tell me enough. There's no need to abbreviate. selectcmd doesn't follow Microsoft's rules about compound words, and dttemp even contains the dreaded "temp".
You haven't encapsulated the MySqlCommand which creates the table in a using.
MySqlCommandBuilder inherits from a class that implements IDisposable, so perhaps that too should be used in a using statement?