本文介绍了将Excel文件转换为asp.net中的数据库时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用框架3.5和sql express 2008将Excel Doc转换为数据库,而当我尝试运行它时却出现以下异常:

找不到可安装的ISAM."

我使用的代码是:

SqlConnection con =新的SqlConnection(ConfigurationManager.ConnectionStrings ["Homeconstr"].ConnectionString);
字符串路径= FileUpload1.FileName.ToString();
字符串xlconst = @数据源=" +路径+; Provider = Microsoft.ACE.OLEDB.12.0;扩展属性= Excel 12.0;";
OleDbConnection xlcon =新的OleDbConnection(xlconst);
OleDbCommand xlcom =新的OleDbCommand(从* [Sheet1 $]中选择*",xlcon);
xlcon.Open(); //异常发生在这里
OleDbDataReader dr;
dr = xlcom.ExecuteReader();
SqlBulkCopy bk =新的SqlBulkCopy(con);
bk.DestinationTableName ="emp_tracker";
bk.WriteToServer(dr);
xlcon.Close();

I am Trying to convert Excel Doc to database I m using framework 3.5 and sql express 2008, when I m trying to run it is giving me following Exception :

"Could not find installable ISAM.."

the code I M using is :

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Homeconstr"].ConnectionString);
string path = FileUpload1.FileName.ToString();
string xlconst = @"Data Source=" + path + ";Provider=Microsoft.ACE.OLEDB.12.0; Extended Properties=Excel 12.0;";
OleDbConnection xlcon = new OleDbConnection(xlconst);
OleDbCommand xlcom = new OleDbCommand("Select * from [Sheet1$]", xlcon);
xlcon.Open(); //Exception Occuring here
OleDbDataReader dr;
dr = xlcom.ExecuteReader();
SqlBulkCopy bk = new SqlBulkCopy(con);
bk.DestinationTableName = "emp_tracker";
bk.WriteToServer(dr);
xlcon.Close();

推荐答案



这篇关于将Excel文件转换为asp.net中的数据库时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 02:29