本文介绍了将Excel数据上传到gridview时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 大家好, 早上好... 我正在开发一个页面,用于将excel文件数据上传到gridview,是代码.. string connString =; string strFileType = Path.GetExtension(FileuplaodControl.FileName).ToLower(); string path = FileuplaodControl.PostedFile.FileName; // Excel工作簿的连接字符串 if(strFileType.Trim()==。xls) { connString =Provider = Microsoft.Jet.OLEDB.4.0 ;数据源=+路径+;扩展属性= \Excel 8.0; HDR =是; IMEX = 2 \; } else if(strFileType.Trim()==。xlsx) { connString =Provider = Microsoft.ACE.OLEDB.12.0; Data Source = + path +;扩展属性= \Excel 12.0; HDR =是; IMEX = 2 \; } OleDbConnection con = new OleDbConnection(connString); OleDbCommand cmdnew = new OleDbCommand(); cmdnew.CommandType = System.Data.CommandType.Text; cmdnew.Connection = con; OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmdnew); DataTable dtExcelRecords = new DataTable(); con.Open(); DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null); string getExcelSheetName = dtExcelSheetName.Rows [0] [Table_Name]。ToString(); cmdnew.CommandText =SELECT * FROM [+ getExcelSheetName +]; dAdapter.SelectCommand = cmdnew; dAdapter.Fill(dtExcelRecords); Grd.DataSource = dtExcelRecords; Grd.DataBind(); con.Close(); con.Dispose(); 在线获取错误: con.Open(); 错误:Microsoft Office Access数据库引擎无法打开或写入文件''。它已由其他用户专门打开,或者您需要获得查看和写入其数据的权限。 使用VS 2010和Office 2010 .. 通过观察上面的错误消息,它表明文件可能被打开或者可能没有访问权限,我已经检查了所有方式...但仍然无法解决问题.. 解决方案 ; Hi Everyone,Good morning... I'm developing a page for uploading excel file data to gridview, following is the the code..string connString = ""; string strFileType = Path.GetExtension(FileuplaodControl.FileName).ToLower(); string path = FileuplaodControl.PostedFile.FileName; //Connection String to Excel Workbook if (strFileType.Trim() == ".xls") { connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; } else if (strFileType.Trim() == ".xlsx") { connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; } OleDbConnection con = new OleDbConnection(connString); OleDbCommand cmdnew = new OleDbCommand(); cmdnew.CommandType = System.Data.CommandType.Text; cmdnew.Connection = con; OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmdnew); DataTable dtExcelRecords = new DataTable(); con.Open(); DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString(); cmdnew.CommandText = "SELECT * FROM [" + getExcelSheetName + "]"; dAdapter.SelectCommand = cmdnew; dAdapter.Fill(dtExcelRecords); Grd.DataSource = dtExcelRecords; Grd.DataBind(); con.Close(); con.Dispose();Getting error at line : con.Open();Error:The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.Using VS 2010 and Office 2010..By observing the above error message it states that the file may be opened or may not have access permission, i have checked in all the ways... but still not able to solve the problem.. 解决方案 这篇关于将Excel数据上传到gridview时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 19:06