gpt4 book ai didi

c# - C# 中加载数据 infile 查询时出错

转载 作者:行者123 更新时间:2023-11-29 08:49:31 25 4
gpt4 key购买 nike

我在使用以下代码时遇到问题:-

 private void btnUpload_Click(object sender, EventArgs e)
{

string nm = txtFilename.Text;
string qry = "LOAD DATA INFILE 'D:\\HHTFiles\\" + nm + "' INTO TABLE `table1`.`location`FIELDS TERMINATED BY '-->'LINES TERMINATED BY '\r\n'(Barcode,BinLoc);";
cmd = new OdbcCommand(qry, con);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show(" File loaded successfully...");
}


}

private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openfiledailog1 = new OpenFileDialog();
openfiledailog1.InitialDirectory = "D:\\HHTFiles\\";
openfiledailog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openfiledailog1.FilterIndex = 2;
openfiledailog1.RestoreDirectory = true;

if (openfiledailog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((openfiledailog1.OpenFile()) != null)
{

txtFilename.Text = openfiledailog1.SafeFileName.ToString();

}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}

如果我在查询中给出完整的文件路径,则它可以正常运行:- string qry = "将数据 INFILE 'D:\HHTFiles\ABC.txt' 加载到表 table1.location 字段由 '-->' 行终止于 '\r\n'(条形码,BinLoc);";但当文件路径在字符串变量中传递时,它会抛出错误。

错误:-错误[HY000] [MySQL][ODBC 5.1 驱动程序][mysqld-5.1.48-community]找不到文件“D:HHTFilesABC.txt”(错误代码:2)

最佳答案

@Aghilas 它已经解决了:)虽然我不确定为什么我首先会出错。不管怎样,我只是用“/”替换了“\\”,它运行得很好。

        string nm = txtFilename.Text;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("LOAD DATA INFILE ");
stringBuilder.Append(Path.Combine("'D:/HHTFiles/", nm));
stringBuilder.Append("' INTO TABLE `table1`.`location`FIELDS TERMINATED BY '-->'LINES TERMINATED BY '\r\n'(Barcode,BinLoc);");

关于c# - C# 中加载数据 infile 查询时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11649185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com