ASP中如何将Excel中的数据导入到SQLServer中
我用的如下代码:
<%
set conn=server.createobject( "ADODB.Connection ")
conn.open "Driver={SQL Server};Server=9C1678FB3A5FG46;Database=MyBase;Uid=sa;Pwd=kv3008 "
sql= "SELECT * into newtable FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0 ', 'Data Source=c:\Student.xls;User ID=sa;Password=kv3008;Extended properties=Excel 5.0 ')...xactions "
conn.execute sql
%>
可运行后提示:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server][OLE/DB provider returned message: 无法启动应用程序。工作组信息文件丢失,或是已被其它用户以独占方式打开。]
怎么回事啊,该怎么解决?望高手指教,我的Excel表没有加密。
------解决方案--------------------conn.Open "Provider=Microsoft.Jet.Oledb.4.0; Extended Properties= " "Excel 8.0;HDR=No " "; Data Source= " & Server.MapPath( "upload/ " & Session( "UserName ") & "_ " & strName)
Set rs = conn.Execute( "select * from [sheet1$] ")
Do While rs.EOF = False
For i = 0 To rs.Fields.Count - 1
Response.Write rs.Fields.Item(i).Value & ", "
Next
rs.MoveNext
Loop
rs.Close
Set rs = Nothing