Los encabezados también se insertan en la base de datos mientras se cargan los datos del archivo csv
Frecuentes
Visto 115 equipos
-1
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;
1 Respuestas
1
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 mysql csv or haz tu propia pregunta.
-1 for lack of effort. Pro tip - remove the first line of CSV. - N.B.
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. - N.B.