I need to import two csv files to mysql database table, but when I will import the second file I want to compare it to the first file inserted in the database, and if there is a difference in a row I will insert the row of the second file.
I have tried to import directly the second file, but the result in the database still with data of the first file also not organized.
First, I uploaded and save the first file, then when I uploaded the second file I didn't see in the database table the data correctly of the second file I want a method to update if there is a difference or add new rows if exist in the second file
Here's my method to import and save the first csv file
What I have tried:
private void Import_Bilan_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string file = openFileDialog1.FileName;
string[] f = file.Split('\\');
string fn = f[(f.Length) - 1];
string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string dest = path + @"\upload\" + fn;
File.Copy(file, dest, true);
MessageBox.Show("File Uploaded !!");
File.Copy(file, dest, true);
MySqlConnection con = new MySqlConnection("datasource=localhost;database=altares;port=3306;username=root;password=root;SslMode=none;AllowUserVariables=true");
var msbl = new MySqlBulkLoader(con)
{
TableName = "exercices",
FieldTerminator = ";",
FileName = dest,
NumberOfLinesToSkip = 1,
};
msbl.Columns.AddRange(new[] { "siren", "designation", "annee", "@discard", "@discard", "@discard", "@discard", "@discard", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "Ak", "AL", "AM", "AN", "AO", "AP", "AQ", "AR","@discard", "AT", "AU", "AV", "AW", "AX", "AY", "CS", "CT", "CU", "CV", "BB", "BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BL", "BM", "BN", "BO", "BP", "BQ", "BR", "BS","YP" });
msbl.Load();
con.Close();
MessageBox.Show("Bilan bind to database !!");
}
}