'下(xià)面的(de)[sheet1$],book.xls,abc.mdb根據實際改setconn=server.createobject("adodb.connection") connstr="driver={microsoftexceldriver(*.xls)};
<% '下(xià)面的(de)[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("導入時(shí)間")=Date dbrs.update dbrs.closeEnd Ifrs.MoveNextLooprs.close%>
'下(xià)面的(de)[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("導入時(shí)間")=Date
dbrs.update
dbrs.close
End If
rs.MoveNext
Loop rs.close
看來(lái)樓主真的(de)該先學學asp了(le) 基礎啊。。。
這(zhè)個(gè)隻需要在我3樓的(de)基礎上改一句就行:
If dbrs.eof Then
dbrs.addnew
dbrs("學号")=rs("學号")
dbrs("姓名")=rs("姓名")
dbrs("導入時(shí)間")=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 |