Los encabezados también se insertan en la base de datos mientras se cargan los datos del archivo csv

enter image description here

Here headers are also inserting into database .here uploading the csv file with comma separated data

   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;

preguntado el 12 de junio de 14 a las 11:06

-1 for lack of effort. Pro tip - remove the first line of CSV. -

You are being lazy, that's what. You saw the first line is wrong. So just remove it, don't go immediately ask on internet what's wrong, this isn't your personal debugging service. -

1 Respuestas

Use el NumberOfLinesToSkip property to skip the first line, like so:

copy.NumberOfLinesToSkip = 1;

The use of this property is clearly shown in the documentation for MySQLBulkLoader. You must make a habit of reading the documentation to resolve your queries before you post a question here.

Respondido el 12 de junio de 14 a las 11:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.