我试图将 LOAD DATA INFILE 用作 sotred 程序,但似乎无法完成。然后我尝试了将代码嵌入到应用程序本身的常用方法,就像这样,
conn = new MySqlConnection(connStr);
conn.Open();
MySqlCommand cmd = new MySqlCommand();
cmd = conn.CreateCommand();
string tableName = getTableName(serverName);
string query = "LOAD DATA INFILE '" + fileName + "'INTO TABLE "+ tableName +" FIELDS TERMINATED BY '"+colSep+"' ENCLOSED BY '"+colEncap+"' ESCAPED BY '"+colEncap+"'LINES TERMINATED BY '"+colNewLine+"' ("+colUpFormat+");";
cmd.CommandText = query;
cmd.ExecuteNonQuery();
conn.Close();
保存在字符串变量查询中的生成查询是,
LOAD DATA INFILE 'data_file.csv'INTO TABLE tbl_shadowserver_bot_geo FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '"'LINES TERMINATED BY '\n' (timestamp,ip,port,asn,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,url,agent,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy);
但是现在当我运行程序时,它给出了一个错误消息,
MySQLException(0x80004005) Parameter @dummy must be defined first.
我不知道如何解决这个问题,但是当我直接在 mysql 本身上使用相同的查询时,它工作正常。请帮助我..非常感谢你:)