'下面的[sheet1$],book.xls,abc.mdb根据实际改setconn=server.createobject("adodb.connection") connstr="driver={microsoftexceldriver(*.xls)};
<% '下面的[sheet1$],book.xls,abc.mdb根据实际改set conn=server.createobject("adodb.connection")connstr="driver={microsoft excel driver (*.xls)};dbq="& server.mappath("book.xls")conn.open connstrset conn2=server.createobject("adodb.connection")connstr2="driver={Microsoft Access Driver (*.mdb)};dbq="& server.mappath("abc.mdb")conn2.open connstr2Set rs=Server.CreateObject("ADODB.Recordset")sql="Select * From [sheet1$]"rs.Open sql,conn,1,1Set dbrs=Server.CreateObject("ADODB.Recordset") Do While Not rs.eofsql="select * from xuesheng where [学号]=" & rs("学号")dbrs.Open sql,conn2,1,3If dbrs.eof Then dbrs.addnew dbrs("学号")=rs("学号") dbrs("姓名")=rs("姓名") dbrs("导入时间")=Date dbrs.update dbrs.closeEnd Ifrs.MoveNextLooprs.close%>
'下面的[sheet1$],book.xls,abc.mdb根据实际改
set conn=server.createobject("adodb.connection")
connstr="driver={microsoft excel driver (*.xls)};dbq="& server.mappath("book.xls")
conn.open connstr set conn2=server.createobject("adodb.connection")
connstr2="driver={Microsoft Access Driver (*.mdb)};dbq="& server.mappath("abc.mdb")
conn2.open connstr2 Set rs=Server.CreateObject("ADODB.Recordset")
sql="Select * From [sheet1$]" rs.Open sql,conn,1,1
Set dbrs=Server.CreateObject("ADODB.Recordset")
Do While Not rs.eof
sql="select * from xuesheng where [学号]=" & rs("学号")
dbrs.Open sql,conn2,1,3
If dbrs.eof Then
dbrs.addnew
dbrs("学号")=rs("学号")
dbrs("姓名")=rs("姓名")
dbrs("导入时间")=Date
dbrs.update
dbrs.close
End If
rs.MoveNext
Loop rs.close
看来楼主真的该先学学asp了 基础啊。。。
这个只需要在我3楼的基础上改一句就行:
If dbrs.eof Then
dbrs.addnew
dbrs("学号")=rs("学号")
dbrs("姓名")=rs("姓名")
dbrs("导入时间")=Date
dbrs.update
dbrs.close
Else
response.write rs("学号") & " " & rs("姓名") & "已存在<br />"
End If
EexcelDB = server.mappath("..")&"\"&replace(request("path"),"/","\") set conn2 =server.createobject("adodb.connection") conn2.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &EexcelDB& ";Extended Properties=Excel 8.0" sql = "select * from [sheet1$]" set rs = conn2.execute(sql) strsql = "select * from userinfo" while not rs.eof set rs1 = server.createobject("adodb.recordset") rs1.open strsql,conn,1,3 rs1.addnew rs1("username") = fixsql(rs(0)) rs1("password") = fixsql(rs(1)) rs1("mz")=request("mz") rs1("fl")=request("fl") rs1("lock")=0 rs1.update num=num+1 rs1.close set rs1 = nothing rs.movenext wend conn2.close set conn2 = nothing response.write "<script language='javascript'>" & chr(13) response.write "alert('导入成功,共导入"& num &" 条数据,点击返回');" & Chr(13) response.write "window.document.location.href='index.asp';"&Chr(13) response.write "</script>" & Chr(13) function fixsql(str) dim newstr newstr = str if isnull(newstr) then newstr = "" else newstr = replace(newstr,"'","''") end if fixsql = newstr end function |