Click here to Skip to main content
15,867,879 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my code below... please help.

C#
cmd.CommandText = "LOAD DATA INFILE" + path + "INTO TABLE table1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES(dat1,dat2,dat3,@ts) SET timedtamp = DATE_FORMAT(STR_TO_DATE(@ts,'%d/%m/%Y %H:%i:%s'),'%Y-%m-%d %H:%i:%s')"

        Try
            If conn.State = ConnectionState.Closed Then

                conn.Open()
                cmd.ExecuteNonQuery()
                MsgBox("Data saved successfully.")
                conn.Close()
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
            End
        End Try
    End Sub


What I have tried:

cmd.CommandText = "LOAD DATA INFILE" + path + "INTO TABLE table1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES(dat1,dat2,dat3,@ts) SET timedtamp = DATE_FORMAT(STR_TO_DATE(@ts,'%d/%m/%Y %H:%i:%s'),'%Y-%m-%d %H:%i:%s')"

Try
If conn.State = ConnectionState.Closed Then

conn.Open()
cmd.ExecuteNonQuery()
MsgBox("Data saved successfully.")
conn.Close()
End If

Catch ex As Exception
MsgBox(ex.Message)
End
End Try
End Sub
Posted
Updated 10-Mar-16 22:54pm
Comments
ramen79 11-Mar-16 13:40pm    
thankz for you comment...unfortunately it did not worked with same error,however if the datetime col in csv file is manually formatted to yyyy-mm-dd hh:mm:ss and the code is written as
cmd.CommandText = "LOAD DATA INFILE " + path + " INTO TABLE table1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES(dat1,dat2,dat3,timedtamp)"

it works fine, but it does not sever my purpose...

1 solution

You need a space before and after + path + in your string concatenation e.g.

C#
cmd.CommandText = "LOAD DATA INFILE " + path + " INTO TABLE table1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES(dat1,dat2,dat3,@ts) SET timedtamp = DATE_FORMAT(STR_TO_DATE(@ts,'%d/%m/%Y %H:%i:%s'),'%Y-%m-%d %H:%i:%s')"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900