MySQL Load Data Infile

前端 未结 1 1724
攒了一身酷
攒了一身酷 2020-12-12 00:26

I want to import CSV file into MySQL database but I am getting an error.

This is my method for LOAD DATA INFILE:

public int Import(strin         


        
相关标签:
1条回答
  • 2020-12-12 01:13

    when you are using an address that have space, must use single quotation (') before and after address like this:

    "LOAD DATA INFILE 'c:\users\trabajo\documents\visual studio 2013\Projects\Zen Hardware\Presentation\Tarjetas de Video.csv' INTO TABLE zen_hardware.products FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"

    public int Import(string path)
    {
       try
       {
          string cmd = "LOAD DATA INFILE '" + path + "' INTO TABLE zen_hardware.products FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
          int a = MySqlHelper.ExecuteNonQuery(conn.Connect(),cmd);
          return a;
       }
       catch
       {
          return -1;
       }
    }
    

    Please see the MySQL Manual Page entitled LOAD DATA INFILE Syntax.

    0 讨论(0)
提交回复
热议问题