读书人

ASP导入数据库时间有关问题求解决

发布时间: 2012-09-27 11:11:17 作者: rapoo

ASP导入数据库时间问题,求解决。
以下源代码是一个考勤系统的导入数据库ASP程序,现在导入会有一个问题,就是只能导入日期最新的不同姓名的数据,重复姓名的导入不进去,而我想要实现的功能是把excel表中的数据全部导入到数据库了,请问应该怎么修改代码?

xlsdaokq.asp

JScript code
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!-- #include file="BGMConn.asp" --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">    <head>        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />        <title>导考勤数据程序</title>    </head>    <body>        <%     Set excconn=Server.CreateObject("ADODB.Connection")           '  excStrConn= "Driver={Microsoft Excel Driver (*.xls)};DBQ="&request("file")      excpath=request("a1")     excStrConn= "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(excpath) & ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"                 excconn.Open  excStrConn               '查询excel语句               Set excrs = Server.CreateObject("ADODB.Recordset")                 excSql="select * from [kq$]"                      excrs.Open excSql,excconn,2,2          set rs=server.createObject("ADODB.Recordset")                     do while Not excrs.EOF             flat = 0            sql="select * from namesfz where name='"&excrs(0)&"'"             set rs=server.createObject("ADODB.Recordset")    rs.open sql,conn,1,1                                    if not rs.EOF then '此用户存在                                  'response.write  rs("id")            'if not rs.eof  then    'j=0    sql1="select * from kq where name='"&rs("name")&"'"                set rs1=server.CreateObject("adodb.recordset")         rs1.open sql1,conn,1,3                        do while Not rs1.EOF                   if year(date())= year(rs1("chuqintime"))  and  month(rs1("chuqintime"))=month( year(date())&"-"&request("month_gz")&"-"&day(date()))  then                             flat = 1                                      for t_i=1  to  16                            rs1(t_i+1) = excrs(t_i)                                              next                                 rs1("chuqintime") =( year(date())&"-"&request("month_gz")&"-"&day(date()))                               rs1.update                              'response.write rs1(2)                         ' response.write "<script>alert('更新成功!');location.href='gzmanage.asp';<'/script>"                 end if                           rs1.movenext        loop                                                   if flat<>1 then                               rs1.addnew                       for t=0 to 16                                    rs1(t+1)=excrs(t)                    next                     rs1("chuqintime") =( year(date())&"-"&request("month_gz")&"-"&day(date()))                                                rs1.update                                    end if                                  rs1.close                           set rs1=nothing                            '  response.write "<script>alert('添加成功!');location.href='gzmanage.asp';</'script>"                                     else  '此用户不存在                         sql="select * from cunzainame "                      set kq_rs=server.createObject("ADODB.Recordset")                          kq_rs.open sql,conn,1,3            kq_rs.addnew        kq_rs("name")=excrs(0)        kq_rs.update                          ' response.write kq_rs("name")                            kq_rs.close                                                    end if  '                        rs.close        excrs.MoveNext         Loop            set rs=nothing    set kq_rs=nothing    excrs.close    set excrs=nothing    excConn.close    set excConn=nothing        set cunzai_rs=server.createObject("ADODB.Recordset")                    cunsql="select * from cunzainame "                         cunzai_rs.open cunsql,conn,1,1            %>        <table width="100%" border="0" cellspacing="0" cellpadding="0">            <% do while Not cunzai_rs.EOF %>            <tr>                <td><%= cunzai_rs(1)%></td>                <td><%= cunzai_rs(2)%></td>            </tr>        </table>        <%             cunzai_rs.MoveNext             loop             response.write "以下用户没有注册!数据没有存入数据库!"          cunzai_rs.close        set rss=server.createobject("adodb.recordset")    sql="delete from cunzainame "rss.open sql,conn,1,1set rss=nothing    conn.close    set conn=nothing %>    </body></html> 




[解决办法]
把前面几个判断用户的If注释掉,只留下导入的语句再试试
[解决办法]
试试:
HTML code
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!-- #include file="BGMConn.asp" --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">    <head>        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />        <title>导考勤数据程序</title>    </head>    <body>        <%     Set excconn=Server.CreateObject("ADODB.Connection")           '  excStrConn= "Driver={Microsoft Excel Driver (*.xls)};DBQ="&request("file")      excpath=request("a1")     excStrConn= "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(excpath) & ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"                 excconn.Open  excStrConn               '查询excel语句               Set excrs = Server.CreateObject("ADODB.Recordset")                 excSql="select * from [kq$]"                      excrs.Open excSql,excconn,2,2          set rs=server.createObject("ADODB.Recordset")                     do while Not excrs.EOF             flat = 0            sql="select * from namesfz where name='"&excrs(0)&"'"             set rs=server.createObject("ADODB.Recordset")    rs.open sql,conn,1,1                                    if not rs.EOF then '此用户存在                                  'response.write  rs("id")            'if not rs.eof  then    'j=0    sql1="select * from kq where name='"&rs("name")&"'"                set rs1=server.CreateObject("adodb.recordset")         rs1.open sql1,conn,1,3                        do while Not rs1.EOF                   if 1=1 or year(date())= year(rs1("chuqintime"))  and  month(rs1("chuqintime"))=month( year(date())&"-"&request("month_gz")&"-"&day(date()))  then                             flat = 1                                      for t_i=1  to  16                            rs1(t_i+1) = excrs(t_i)                                              next                                 rs1("chuqintime") =( year(date())&"-"&request("month_gz")&"-"&day(date()))                               rs1.update                              'response.write rs1(2)                         ' response.write "<script>alert('更新成功!');location.href='gzmanage.asp';<'/script>"                 end if                           rs1.movenext        loop                                                   if flat<>1 then                               rs1.addnew                       for t=0 to 16                                    rs1(t+1)=excrs(t)                    next                     rs1("chuqintime") =( year(date())&"-"&request("month_gz")&"-"&day(date()))                                                rs1.update                                    end if                                  rs1.close                           set rs1=nothing                            '  response.write "<script>alert('添加成功!');location.href='gzmanage.asp';</'script>"                                     else  '此用户不存在                         sql="select * from cunzainame "                      set kq_rs=server.createObject("ADODB.Recordset")                          kq_rs.open sql,conn,1,3            kq_rs.addnew        kq_rs("name")=excrs(0)        kq_rs.update                          ' response.write kq_rs("name")                            kq_rs.close                                                    end if  '                        rs.close        excrs.MoveNext         Loop            set rs=nothing    set kq_rs=nothing    excrs.close    set excrs=nothing    excConn.close    set excConn=nothing        set cunzai_rs=server.createObject("ADODB.Recordset")                    cunsql="select * from cunzainame "                         cunzai_rs.open cunsql,conn,1,1            %>        <table width="100%" border="0" cellspacing="0" cellpadding="0">            <% do while Not cunzai_rs.EOF %>            <tr>                <td><%= cunzai_rs(1)%></td>                <td><%= cunzai_rs(2)%></td>            </tr>        </table>        <%             cunzai_rs.MoveNext             loop             response.write "以下用户没有注册!数据没有存入数据库!"          cunzai_rs.close        set rss=server.createobject("adodb.recordset")    sql="delete from cunzainame "rss.open sql,conn,1,1set rss=nothing    conn.close    set conn=nothing %>    </body></html> 


[解决办法]
你的代码里貌似本来就做了用户判断,重复用户不导入

读书人网 >ASP

热点推荐