此处标题也插入到数据库中。其中使用逗号分隔数据上传csv文件
string Feedback = string.Empty;
string connString = ConfigurationManager.ConnectionStrings["DataBaseConnectionString"].ConnectionString;
using (MySqlConnection conn = new MySqlConnection(connString))
{
var copy = new MySqlBulkLoader(conn);
conn.Open();
try
{
copy.TableName = "BulkImportDetails";
copy.FileName = fileName;
copy.FieldTerminator = ",";
copy.LineTerminator = @"\n";
copy.Load();
Feedback = "Upload complete";
}
catch (Exception ex)
{
Feedback = ex.Message;
}
finally { conn.Close(); }
}
return Feedback;
答案 0 :(得分:1)
使用NumberOfLinesToSkip
属性跳过第一行,如下所示:
copy.NumberOfLinesToSkip = 1;
MySQLBulkLoader
的文档中清楚地显示了此属性的使用。在此处发布问题之前,您必须养成阅读文档的习惯以解决您的疑问。