I am trying to insert a C # table into MySQL. For this I am using a txt file filled with the table information and then inserting into MySQL, but it does not insert even though the file is created correctly. >
Below is 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();
}