Jul 2

Excel数据导入到SQL Server数据库中 晴

admin365 , 02:31 , Excel , 评论(0) , 引用(0) , 阅读(64) , Via 本站原创 | |



[转载]

Excel数据导入到SQL Server数据库中,代码如下:

1)接受数据导入的表已经存在。
insert into 表 select * from OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,
'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$);

2)导入数据并生成表。
select * into 表 from OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,
'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$);


3) 导入Excel中指定的列到数据库表中指定的列。
INSERT INTO 表(a1,a2,a3) SELECT a1,a2,a3 FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,
'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$);

需要注意的地方。
1)外围应用配置器的设置。
从“功能外围应用配置器”中选择“启动 OPENROWSET 和 OPENDATASOURCE 支持”选项。
2)关闭Excel表。
如果在导入时要导入的Excel表格处于打开状态,会提示:
“无法初始化链接服务器 "(null)" 的 OLE DB 访问接口 "microsoft.jet.oledb.4.0" 的数据源对象。”
3)导入数据时,Excel的首行会作为表头,若导入到已存在的数据库表,则忽略首行。


[转载]原文链接: http://talenyi.blog.163.com/blog/static/59447208200853095655329

百度搜索:Excel
Google搜索:Excel
雅虎搜索:Excel
SOSO搜索:Excel



Tags:
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]