Insert Into OpenRowSet('Microsoft.Jet.OLEDB.4.0','Excel 5.0;hdr=Yes;DataBase=C:\test.xls',test$)
select * from T_test
还是把Excel的资料插入Sql Server表:select * from T_test
Insert Into T_test
select * from OpenRowSet('Microsoft.Jet.OLEDB.4.0','Excel 5.0;hdr=Yes;DataBase=C:\test.xls',test$)
select * from OpenRowSet('Microsoft.Jet.OLEDB.4.0','Excel 5.0;hdr=Yes;DataBase=C:\test.xls',test$)
都有可能会遇见字段混乱的问题,
即:Sql Server表和Excel的字段顺序不一样!
其实,出现这样的问题,是对OpenRowSet 的使用不甚了解引起的!
hdr = Yes 表示Excel内容第一行作为内容字段而不是字段列,
所以,把 hdr = Yes 改为 hdr = No 即可!