OleDB中的连接字符串错误

时间:2015-06-05 05:43:47

标签: import excel-2010 connection-string oledb

我正在尝试通过asp.net代码Import Excel文件。但是当我尝试创建ArgumentException

时,我收到OleDbConnection
  

ConnectionString中未指定OLE DB提供程序。一个   例如,'提供商= SQLOLEDB;'。

这是代码

if (FileUpload1.HasFile) 
            {
                string path = string.Concat((Server.MapPath("~/temp/"+FileUpload1.FileName)));
                FileUpload1.PostedFile.SaveAs(path);
                OleDbConnection oleCon = new OleDbConnection("Povider=Microsoft.Ace.OLEDB.12.0;Data Source="+path+";Extended Properties = Excel 12.0;");
                OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]",oleCon);
                OleDbDataAdapter dtap = new OleDbDataAdapter(cmd);
                oleCon.Open();
                DbDataReader rdr = cmd.ExecuteReader();
                string con_str = @"Data source = .;Initial Catalog=practiceDB;Integrated security=True";
                SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
                bulkInsert.DestinationTableName="Excel";
                bulkInsert.WriteToServer(rdr);
                oleCon.Close();
                Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))),File.Delete);
                Response.Write("<script>alert('Inserted')</script>");

0 个答案:

没有答案