It may not insert the data, if your csv file and the mysql table columns are not matched.
For example if your mysql table has a primary key column with identity key, and generally you won't have this column in csv file.
So in the above case the mysqlloader will not insert the data.
To solve this use columns property and add the columns mysql table column names
here is a sample code.
public async Task<bool> MySqlBulkLoaderAsync(string csvFilePath)
{
bool result = true;
try
{
using (var conn = new MySqlConnection(_connString + ";AllowLoadLocalInfile=True"))
{
var bl = new MySqlBulkLoader(conn)
{
TableName = "patientdetailstagings",
Timeout = 600,
FieldTerminator = ",",
LineTerminator = "\n",
FieldQuotationCharacter = '"',
FileName = csvFilePath,
NumberOfLinesToSkip = 1
};
bl.Columns.AddRange(new List<string>() {"Column1", "Column2"});
var numberOfInsertedRows = await bl.LoadAsync();
}
System.IO.File.Delete(csvFilePath);
}
catch (Exception ex)
{
result = false;
throw;
}
return result;
}
Note: the column mapping will be done based on the way you have added them in the columns property.
In the same order it will access the column value from csv file