Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to insert data in a database table from two other tables

Whenever I run my code, it would return this particular error
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll - Additional information: Fatal error encountered during command execution.
exception image:[^]

which is pointed at
What could be the problem here? Here's my code

What I have tried:

private void Merge_Tables_Click(object sender, EventArgs e)

                string MergeTables = (@"INSERT INTO exercices (annee,AA,region) 
                SELECT e1.annee,e1.AA,e2.region
                FROM bilan e1 JOIN data e2
                ON e1.siren = e2.siren");

                string serverIp = "";
                string username = "root";
                string password = "root";
                string databaseName = "altares";

                string dbConnectionString = string.Format("server={0};uid={1};pwd={2};database={3};SslMode=none", serverIp, username, password, databaseName);

                var conn = new MySqlConnection(dbConnectionString);

                var cmd = new MySqlCommand(MergeTables, conn);


                MessageBox.Show("Table exercices now with data !!");

Updated 19-Sep-18 1:33am
Leo Chapiro 19-Sep-18 8:27am    
Have you tried to execute this statement by SQL Management Studio (MS SQL Server) directly?
ZurdoDev 19-Sep-18 8:57am    
Your exception has an InnerException. Check to see if that Exception also has an InnerException. Get to the innermost exception and then google the error. I saw lots of possible reasons.
Member 14048200 26-Feb-19 6:28am    
unhelpful google gets me here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900