开发者

problem with mysql export to file in c#

i have a problem with mysql+c# in mysql export operation.

FolderBrowserDialog fol=new FolderBrowserDialog();
if (fol.ShowDialog() == DialogResult.OK)
{
   string path= fol.SelectedPath;
   string sql = "SELECT * INTO OUTFILE '" + path+ "\person.csv' FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '\"' LINES开发者_开发百科 TERMINATED BY '\n' FROM tpers ";
   MySqlCommand daa = new MySqlCommand(sql, conn);
   conn.Open();
   daa.ExecuteNonQuery();
   conn.Close();                              
}

for example

path = "c:\export"

but when i execute this code it doesnt export person.csv to intended path.

it creates "c:export\person.csv" file and creates this file in mysql/data folder..

can u explain the problem, and how to fix it...


I solved this problem..

string path = fol.SelectedPath;
path = path.Replace("\\","/");
...

after this my program works correctly...


Works for me!! In my case needed to do in c#. Used with the MySql.Data.dll v6.4.4

LOAD DATA LOCAL INFILE 'C:/Program Files/MySQL/MySQL Server 5.7/bin/test.csv' REPLACE INTO TABLE test_tmp CHARACTER SET UTF8  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES (field1,field2,field3,field4,field5);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜