C#中从xlsx文件获取记录时出错
当我尝试从 xlsx 文件中读取记录时出现错误。
错误为“无法更新。数据库或对象是只读的。”
我已验证该文件不是只读的。有什么想法可能导致错误吗?
我的代码是:
string strFileName = System.IO.Path.GetFileName(txtSourcePath.Text);
string strFilePath = txtSourcePath.Text;
string strDirectoryPath = strFilePath.Substring(0, (txtSourcePath.TextLength - (strFileName.Length + 1)));
string conn = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=""text;HDR=YES;FMT=DELIMITED""", strDirectoryPath);
OleDbConnection oleDBConn = new OleDbConnection(conn);
oleDBConn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select * FROM [" + strFileName + "]", conn);
DataSet ds = new DataSet();
da.Fill(ds);
当我将鼠标悬停在 ds
上时,我看不到任何记录
I am getting an error when I attempt to read the records from my xlsx file.
The error is "Cannot update. Database or object is read-only."
I have verified that the file is not read-only. Any ideas what could be causing the error?
My code is:
string strFileName = System.IO.Path.GetFileName(txtSourcePath.Text);
string strFilePath = txtSourcePath.Text;
string strDirectoryPath = strFilePath.Substring(0, (txtSourcePath.TextLength - (strFileName.Length + 1)));
string conn = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=""text;HDR=YES;FMT=DELIMITED""", strDirectoryPath);
OleDbConnection oleDBConn = new OleDbConnection(conn);
oleDBConn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select * FROM [" + strFileName + "]", conn);
DataSet ds = new DataSet();
da.Fill(ds);
When I hover over ds
I don't see any records
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要安装:microsoft.ace.oledb.12.0 驱动程序
替换你的excel文件路径的路径
Required to install : microsoft.ace.oledb.12.0 driver
Replace Path of your excel file path