gpt4 book ai didi

c# - 错误 :Make sure that it does not include invalid characters or punctuation and that it is not too long

转载 作者:太空宇宙 更新时间:2023-11-03 23:24:25 24 4
gpt4 key购买 nike

我尝试使用 oledb 获取 excel 工作表名称。

我的连接字符串是:

string ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

其中 filepath 是一个文件名。

我的代码:

 OleDbCommand cmd = new OleDbCommand(@"SELECT * FROM [Employee$]", conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(Data);

在这行报错

adapter.Fill(Data);

错误是

'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: 'Employee$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

如何做到这一点?

最佳答案

试试这个:

 OleDbCommand cmd = new OleDbCommand(@"SELECT * FROM [dataGridView1_Data$]", conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(Data);

关于c# - 错误 :Make sure that it does not include invalid characters or punctuation and that it is not too long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34306449/

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