1

I have this file in csv trying to import to using load data infile syntax. but I am stuck with this error in syntax. I tried every thing but no luck.Any help would be appreciated.

string strLoadData = "LOAD DATA LOCAL  INFILE 'C:/xampp/htdocs/explortest.csv' INTO  test.tickets FIELDS  terminated by ',' ENCLOSED BY '\"'  lines terminated by '\r\n' ignore 1 lines  ";

ERROR

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'test.tickets FIELDS  terminated by ',' ENCLOSED BY '"'  lines terminated by '
'' at line 1

3 Answers 3

1
string strLoadData = "...";

The C# compiler will look for escape sequences in strLoadData and replace them with special characters. Thus your \r\n would be interpreted by C# as "new line" and "line feed" characters. But you need MySQL to read "\r\n" not "new line" and "line fead" characters - to apply it's own escape sequences interpretation.

Long story short: replace \r\n with \\r\\n

Sign up to request clarification or add additional context in comments.

Comments

0

Add TABLE After INTO

LOAD DATA LOCAL  INFILE 'C:/xampp/htdocs/explortest.csv' 
INTO TABLE test.tickets FIELDS  terminated by ',' ENCLOSED BY '\"'  lines terminated by '\r\n' ignore 1 lines 

Comments

0

Check the line terminates character in file. Are you sure that is \r\n? Maybe you have \n or \r as line termination on your file.

You can read more here. I'm copying a part of this page below:

Note

If you have generated the text file on a Windows system, you might have to use LINES TERMINATED BY '\r\n' to read the file properly, because Windows programs typically use two characters as a line terminator. Some programs, such as WordPad, might use \r as a line terminator when writing files. To read such files, use LINES TERMINATED BY '\r'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.