帮我看看导入问题

njhyh 2005-07-23 01:35:30
下面是我的代码:老是有错误!可否帮忙改一下!
<!--#include file="Conn.asp"-->
<%
dim Rs,RsExcel,RsExcelConn,Str
Connection()
Set Rs=Server.CreateObject("Adodb.Recordset")
Set RsExcel=Server.CreateObject("Adodb.Recordset")
RsExcelConn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Book1.xls") & ";Extended properties=Excel 8.0"

Str="SELECT * into test FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="E:\评测\book1.xls";User ID=Admin;Password=;Extended properties=Excel 8.0')……[sheet1$] "
rsExcel.open Str,1,3
rsExcel.close
rs.close
%>


'conn.asp的代码如下:
<%@ LANGUAGE = VBScript%>
<%
Option Explicit
Response.Buffer = True
Public ConValue,conn,UN '连接成功返回值,数据库连接变量(公共变量)
'========================定义数据库类别,1为SQL数据库,0为Access数据库=============================
Const IsSqlDataBase = 1
'=============================================================================================
If IsSqlDataBase = 1 Then
'========================SQL数据库设置=========================================================
'sql数据库连接参数:数据库名(SqlDatabaseName)、用户密码(SqlPassword)、用户名(SqlUsername)、
Const SqlDatabaseName="TestDB"
Const SqlPassword=""
Const SqlUsername = "sa"
Const SqlLocalName = "(local)"
End If

public Function Connection()
Dim ConnStr '私有变量

connStr = "Provider = Sqloledb.1; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"

on Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr

If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"'注释,需要把这几个字翻译成英文。
ConValue=0 '连接失败返回值
Response.End
End If
ConValue=1
end function
%>
...全文
130 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
renniliao 2005-07-24
  • 打赏
  • 举报
回复
注:上面代码转自
http://community.csdn.net/Expert/topic/3722/3722309.xml?temp=.9665796
中birdfly8() 的回答
renniliao 2005-07-24
  • 打赏
  • 举报
回复
换这个试试:
<%
Set Conn1= Server.CreateObject("ADODB.Connection")
Driver ="Driver={Microsoft Excel Driver (*.xls)};"
DBPath ="DBQ="&Server.MapPath("files\excel.xls")
Conn1.Open Driver&DBPath

Set rs= Server.CreateObject("ADODB.Recordset")
Sql="insert into test select * from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=yes;DATABASE=d:\kaifa\files\excel.xls',sheet1$)"
conn.execute sql
%>
njhyh 2005-07-23
  • 打赏
  • 举报
回复
谢谢您:我试过了!但是又有下面的问题:
'---------------------------------------------
服务器: 消息 7399,级别 16,状态 1,行 3
OLE DB 提供程序 'Microsoft.Jet.OLEDB.4.0' 报错。
[OLE/DB provider returned message: 找不到可安装的 ISAM。]

请问:可知是什么原因???
renniliao 2005-07-23
  • 打赏
  • 举报
回复
你的str拼接的有问题啊。
这样改:
Str="SELECT * into test FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=E:\评测\book1.xls;User ID=Admin;Password=;Extended properties=Excel 8.0')…[sheet1$] "
或者:
dim strExcelPath
strExcelPath=E:\评测\book1.xls"
Str="SELECT * into test FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" & strExcelPath & ";User ID=Admin;Password=;Extended properties=Excel 8.0')…[sheet1$] "
njhyh 2005-07-23
  • 打赏
  • 举报
回复
错误提示:
'----------------------------------------------
Microsoft VBScript 编译器错误 错误 '800a03f6'

缺少 'End'

/iisHelp/common/500-100.asp,行242

Microsoft VBScript 编译器错误 错误 '800a0401'

语句未结束

/njh/DTS.asp,行11

Str="SELECT * into test FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="E:\评测\book1.xls";User ID=Admin;Password=;Extended properties=Excel 8.0')…[sheet1$] "
---------------------------------------------------------------------------------^
renniliao 2005-07-23
  • 打赏
  • 举报
回复
错误是什么啊?错误提示呢?多少行?
njhyh 2005-07-23
  • 打赏
  • 举报
回复
急需解决!不解决我睡不着觉,拜托大家了。

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧