Insert into Mysql txt file

Asked

Viewed 35 times

0

I’m trying to insert a C# table into Mysql. For this I am using a txt file filled with table information and then inserting in Mysql, but it does not insert even though the file is created correctly.

Below follows the code I’m using:

public static void upload_cessao()
{
    String nameFileAndPath = @"C:\Users\ferre\Documents\WorkPerormance_TEMP.txt";
    if (!File.Exists(nameFileAndPath))
    {
        File.Create(nameFileAndPath);
    }
    StreamWriter strWriter = new StreamWriter(nameFileAndPath);
    strWriter.WriteLine("Ficheiro temporário da base de dados.");
    for (int i = 0; i < Tcessao.Rows.Count; i++)
    {
        DataRow row = Tcessao.Rows[i];
        strWriter.WriteLine("{0};{1};{2};{3};{4};{5}",
            row["idcessao"].ToString(),
            row["timeLogin"].ToString(),
            row["timeLogout"].ToString(),
            row["appMouse_idappMouse"].ToString(),
            row["appKeyboard_idappKeyboard"].ToString(),
            row["user_login"].ToString());
    }
    strWriter.Close();
    strWriter.Dispose();
    StreamReader strReader = new StreamReader(nameFileAndPath);
    MessageBox.Show(strReader.ReadLine());

    MySqlConnection coon = Conexao.obterConexao();
    MySqlBulkLoader LoadData = new MySqlBulkLoader(coon);
    LoadData.TableName = "cessao";
    LoadData.FieldTerminator = ";";
    LoadData.LineTerminator = "\r\n";
    LoadData.NumberOfLinesToSkip = 1;
    LoadData.ConflictOption = MySqlBulkLoaderConflictOption.None;
    LoadData.FileName = nameFileAndPath;
    LoadData.Priority = MySqlBulkLoaderPriority.Low;
    LoadData.Load();
    Conexao.fecharConexao();
}
  • what error is giving?

  • No error. The application runs normally but no data is inserted into mysql. If I go see the file that was created the information is all there.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.