Microsoft Access数据库引擎找不到对象'Sheet1 $ [英] The Microsoft Access database engine could not find the object 'Sheet1$

查看:310
本文介绍了Microsoft Access数据库引擎找不到对象'Sheet1 $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将保存在服务器文件夹中的excel模板文件复制到具有不同名称的同一文件夹中.插入值..我能够复制文件,但是当我尝试插入值时,它显示sheet!$找不到.我给了正确的工作表名称.在电子表格中仅添加了一张工作表,命名为sheet1.仍然显示错误.我的代码如下...这只是正确的..请帮助我

I am copying the template excel file saved in the server folder in to the same folder with different name. to insert the value..I am able to copy the file but when I try to insert the values it shows sheet!$ could not found. I have given correct sheet name..Only one sheet is added in the spread sheet named as sheet1.still it shows error .My code is given below.Nay idea about this error .I googled but asked me to check the folder and sheet name..it is correct only..please help me

        string xxx = "~/temp/" + "Tempfile" + dunsno + DateTime.Today.ToString("dd.MM.yyyy") + ".xlsx";
         DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath("~/temp/"));
                            var fileList = directoryInfo.GetFiles();
                            string newFileName = Server.MapPath("~/temp/" + "Tempfile" + dunsno + DateTime.Today.ToString("dd.MM.yyyy") + ".xlsx");
                            foreach (FileInfo fleInfo in fileList     

                       {
                                fleInfo.CopyTo(newFileName, true);
                       }
         string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=xxx;Extended Properties=""Excel 12.0 Xml;HDR=YES""");
         OleDbConnection MyConnection;
                            OleDbCommand MyCommand = new OleDbCommand();
                            MyConnection = new OleDbConnection(@connStr);

                            MyConnection.Open();
                            MyCommand.Connection = MyConnection;
                            string sql = "Insert into [Sheet1$] (id,name) values('3','c')";
                            MyCommand.CommandText = sql;
                            MyCommand.ExecuteNonQuery();
                            MyConnection.Close();

推荐答案

替换:

string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=xxx;Extended Properties=""Excel 12.0 Xml;HDR=YES""");

使用

string connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES""", newFileName);

这篇关于Microsoft Access数据库引擎找不到对象'Sheet1 $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆