ASP.NET导入excel数据到Sql server2005
2013-01-19 18:26
357 查看
//将excel中的内容导入到数据库中
//得到要导入的excel文件的文件路径
String importurl = this.FileUpload_ImportRecord.PostedFile.FileName;
//连接数据库,并把excel插入到相应的表中
SqlConnection con = new SqlConnection("server=localhost\\SQLEXPRESS;Database=考勤系统;uid=sa;password=111111");
String sqlstr="insert into PeopleManage(Partment,PeopleNum,LoginNum,Name,Sex,Date,Bus,Rest,VersionNum,Kong1,Kong2,
Kong3,Kong4,Kong5) select 部门,姓名,编号,登记号码,卡片号码,考勤制度,默认考勤,默认公休,性别,入职日期,职务,出生日期,证件号,
联系电话 from openrowset('microsoft.jet.oledb.4.0','excel 5.0;IMEX=1;HDR=YES;database=d:\\111.xls',[sheet1$])";
SqlCommand cmd = new SqlCommand(sqlstr, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
启用Ad Hoc Distributed Queries:
完成后,关闭Ad Hoc Distributed Queries:
//得到要导入的excel文件的文件路径
String importurl = this.FileUpload_ImportRecord.PostedFile.FileName;
//连接数据库,并把excel插入到相应的表中
SqlConnection con = new SqlConnection("server=localhost\\SQLEXPRESS;Database=考勤系统;uid=sa;password=111111");
String sqlstr="insert into PeopleManage(Partment,PeopleNum,LoginNum,Name,Sex,Date,Bus,Rest,VersionNum,Kong1,Kong2,
Kong3,Kong4,Kong5) select 部门,姓名,编号,登记号码,卡片号码,考勤制度,默认考勤,默认公休,性别,入职日期,职务,出生日期,证件号,
联系电话 from openrowset('microsoft.jet.oledb.4.0','excel 5.0;IMEX=1;HDR=YES;database=d:\\111.xls',[sheet1$])";
SqlCommand cmd = new SqlCommand(sqlstr, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问
解决这个问题的方法:启用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure
完成后,关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure
相关文章推荐
- ASP.NET中数据库数据导入Excel并打印
- ASP.NET Excel数据导入数据库
- asp.net 解决使用OLEDB导入excel数据时同时包含文本和数字的列无法正常读取情况
- ASP.NET 从Excel文件导入数据到数据库(笔记)
- ASP.NET中数据库数据导入Excel并打印
- asp.net使用组件koogra读取Excel数据批量上传导入
- Asp.net中关于excel文件批量导入SQL Server数据表
- asp.net 将Excel数据导入到GridView和SQL数据库
- C#数据库数据导入导出系列之一 ASP.NET Excel导入Sql Server数据库
- ASP.NET中数据库数据导入Excel并打印
- [导入]asp.net 把datatable的数据导出到EXCEL
- sql sever2005中批量导入excel表格数据(Asp.net C#)
- asp.net<Web版> ---将excel表数据导入到数据库问题<一>---未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0” 提供程序
- asp.net采用OLEDB方式导入Excel数据时提示:未在本地计算机上注册"Microsoft.Jet.OLEDB.4.0" 提供程序"
- asp.net从excel导入数据
- ASP.NET中数据库数据导入Excel并打印
- asp.net mvc 数据导出excel表及自excel表导入数据到相应表
- asp.net EXCEL数据 导入到数据库
- 在asp.net中导入Excel数据到gridiew中
- ASP.Net杂谈之 — 10W条数据拷贝效率测试(接上篇 “Linq杂谈之 — Linq导入Excel”)