c# - convert datetime format from csv to mysql database -


i exporting data csv datetime in format

20/02/2012 16:42:10, 

and mysql table date format

2013-11-04 10:00:52  after exporting displayed 0000-00-00 00:00:00 

full code after edited

// mysqlconnection conn = new mysqlconnection("data source = ; database = ;uid= ;pwd=faithful ;convert 0 datetime=true;");         mysqlconnection conn = new mysqlconnection("data source =; database =;uid=root ;pwd=h0tjava1;convert 0 datetime=true;");          datatable db = new datatable();           string strloaddata = "load data local  infile 'i:/kiran/final test/finaltest12.csv' table tickets  fields  terminated ',' enclosed '\"'  lines terminated '\n' ignore 1 lines (siteid,@vardatetime,serial,deviceid,agentaid,vehicleregistration,carpark,spacenumber,gpsaddress,vehicletype,vehiclemake,vehiclemodel,vehiclecolour,issuereasoncode,issuereason,noticelocation,points,notes) set datetime  =  str_to_date(@vardatetime,'%d/%m/%y %h:%i:%s');";         mysqlcommand cmd1 = new mysqlcommand(strloaddata, conn);           cmd1.commandtimeout = 6000;           cmd1.connection = conn;         conn.open();         cmd1.prepare();         cmd1.executenonquery();         conn.close(); 

error

fatal error encountered during command execution. @ line cmd1.executenonquery(); 

try below

load data local  infile 'f:/explor/final test/finaltest12.csv'  table tickets  fields  terminated ',' enclosed '\"'  lines terminated '\n'  ignore 1 lines  (siteid,@vardatetime,serial,deviceid,agentaid,vehicleregistration,carpark,spacenumber,gpsaddress,vehicletype,vehiclemake,vehiclemodel,vehiclecolour,issuereasoncode,issuereason,noticelocation,points,notes) set datetime  =  str_to_date(@vardatetime,'%d/%m/%y %h:%i:%s'); 

here datetime name of column.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -