标题也在上传csv文件数据时插入数据库

时间:2014-06-12 10:09:20

标签: mysql csv

enter image description here

此处标题也插入到数据库中。其中使用逗号分隔数据上传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;

1 个答案:

答案 0 :(得分:1)

使用NumberOfLinesToSkip属性跳过第一行,如下所示:

copy.NumberOfLinesToSkip = 1;

MySQLBulkLoader的文档中清楚地显示了此属性的使用。在此处发布问题之前,您必须养成阅读文档的习惯以解决您的疑问。