1个回答
展开全部
这段代码已经测试过:excel导入到access数据库
<%
dim FileName
FileName="data.xls" '取得文件名,来自项目经理的指定,路径固定在某个虚拟路径中
Dim conn, rs
set conn=CreateObject("ADODB.connection")
conn.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
"DriverId=790;" & _
"Dbq=" & Server.mappath(""&FileName&"") & ";" & _
"DefaultDir=c:\"
set rs=createobject("ADODB.recordset")
rs.Open "Select * From [snew$]",conn, 2, 2
if rs.eof then
response.write "Excel表中无纪录"
else
set connDB = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("data1.mdb")
'RESPONSE.WRITE DBpath
connDB.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
Set RsDB = Server.CreateObject("ADODB.Recordset")
SQLDB="Select * from test"
RsDB.open SQLDB,connDB,1,3
do while not rs.eof '利用循环读出数据
RsDB.addnew
RsDB("0")=rs(0)
RsDB("1")=rs(1)
RsDB("2")=rs(2)
RsDB("3")=rs(3)
'RsDB("id4")=rs(4)
Rs.update
RsDB.movenext
rs.movenext
loop
'response.redirect FileName
end if
RsDB.movefirst
if RsDB.eof then
response.write "数据库中无记录"
else
do while not RsDB.EOF
response.write RsDB("0")&" "
response.write RsDB("1")&" "
response.write RsDB("2")&" "
response.write RsDB("3")&" "
'response.write RsDB("id4")&" "
response.write "<br>"
RsDB.movenext
loop
end if
rs.close
set rs=nothing
set conn=nothing
%>
<%
dim FileName
FileName="data.xls" '取得文件名,来自项目经理的指定,路径固定在某个虚拟路径中
Dim conn, rs
set conn=CreateObject("ADODB.connection")
conn.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
"DriverId=790;" & _
"Dbq=" & Server.mappath(""&FileName&"") & ";" & _
"DefaultDir=c:\"
set rs=createobject("ADODB.recordset")
rs.Open "Select * From [snew$]",conn, 2, 2
if rs.eof then
response.write "Excel表中无纪录"
else
set connDB = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("data1.mdb")
'RESPONSE.WRITE DBpath
connDB.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
Set RsDB = Server.CreateObject("ADODB.Recordset")
SQLDB="Select * from test"
RsDB.open SQLDB,connDB,1,3
do while not rs.eof '利用循环读出数据
RsDB.addnew
RsDB("0")=rs(0)
RsDB("1")=rs(1)
RsDB("2")=rs(2)
RsDB("3")=rs(3)
'RsDB("id4")=rs(4)
Rs.update
RsDB.movenext
rs.movenext
loop
'response.redirect FileName
end if
RsDB.movefirst
if RsDB.eof then
response.write "数据库中无记录"
else
do while not RsDB.EOF
response.write RsDB("0")&" "
response.write RsDB("1")&" "
response.write RsDB("2")&" "
response.write RsDB("3")&" "
'response.write RsDB("id4")&" "
response.write "<br>"
RsDB.movenext
loop
end if
rs.close
set rs=nothing
set conn=nothing
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询