Alexios.W
2022-05-19 11:44
采纳率: 100%
浏览 73

用C#将csv文件导入mysql报错:No such file or directory

问题遇到的现象和发生背景

我把csv文件放在了项目的debug下

img

csv文件如下所示:

img

问题相关代码
private void btn_LoadCSV_Click(object sender, EventArgs e)
        {
            CreatedMysqlTable();    //创建表test

            //读取CSV文件
            MySqlBulkLoader bulkLoader = new MySqlBulkLoader(msc);
            bulkLoader.TableName = "test"; //插入的表的名字

            OpenFileDialog file = new OpenFileDialog();
            file.ShowDialog();
            string fullname = file.FileName;
            //string path = System.IO.Path.GetDirectoryName(fullname);
            //string name = System.IO.Path.GetFileName(fullname);
            bulkLoader.FileName = fullname; //路径

            //bulkLoader.FileName = Environment.CurrentDirectory + "\\" + "test.csv";

            bulkLoader.FieldTerminator = ","; //字段间的间隔方式 This can be { comma,tab,semi colon, or other character}
            bulkLoader.LineTerminator = "\n";
            int count = bulkLoader.Load();  //执行
        }

运行结果及报错内容

img

“MySql.Data.MySqlClient.MySqlException”类型的未经处理的异常在 MySql.Data.dll 中发生
File 'D:\Work\研究生\CS与MySQL\Mysql\Mysql\bin\Debug\test.csv' not found (OS errno 2 - No such file or directory)

img

辛苦各位帮忙解决了!

5条回答 默认 最新

相关推荐 更多相似问题