注册 登录
编程论坛 ASP技术论坛

为什么我用for循环导入的数据都是第一行的?

天上的星 发布于 2009-08-28 16:10, 544 次点击
Set excconn=Server.CreateObject("ADODB.Connection")
      excStrConn= "Driver={Microsoft Excel Driver (*.xls)};DBQ="& request("file")
    excconn.Open  excStrConn
     '查询excel语句   
   
     Set excrs = Server.CreateObject("ADODB.Recordset")     
     excSql="select * from [080927$]"     
    excrs.Open excSql,excconn,2,2
                     
        set rs=server.createObject("ADODB.Recordset")         
       if request("xq")="first1" then
            sql="select * from  first1 "
      
        end if
      
        rs.open sql,conn,1,3                 
            for i=1 to 50
                rs.addnew               
                    for t=0 to 10                  
                    rs(t+1)=excrs(t)           
                    next
                    rs("time")=now()
            
                rs.update
            next
        rs.close
        set rs=nothing   
      
    excrs.close
    set excts=nothing
   
    excconn.close
    set excconn=nothing   
    conn.close
    set conn=nothing
   
        
4 回复
#2
yms1232009-08-28 16:17
        rs.open sql,conn,1,3                 
            for i=1 to 50
                rs.addnew               
                    for t=0 to 10                  
                    rs(t+1)=excrs(t)           
                    next
                    rs("time")=now()
               
                rs.update
            next
        rs.close
        set rs=nothing  
循环本身就有问题,这样循环50次肯定导入50次第一行
        rs.open sql,conn,1,3                  
            Do until execrs.eof
                rs.addnew               
                    for t=0 to 10                  
                    rs(t+1)=excrs(t)            
                    next
                    rs("time")=now()
               
                rs.update
                excrs.movenext
            loop
        rs.close
        set rs=nothing
#3
天上的星2009-08-28 16:29
回复 2楼 yms123
这样的话总是导入很多行空记录,怎么控制?要不我也不会用for来做了!
#4
yms1232009-08-28 16:45
        rs.open sql,conn,1,3                  
            Do until execrs.eof
               if excrs(0)<>Empty and excrs(0)<>"" Then
                  rs.addnew               
                  for t=0 to 10                  
                      rs(t+1)=excrs(t)            
                   next
                   rs("time")=now()
                   rs.update
                end if
                excrs.movenext
            loop
        rs.close
        set rs=nothing
加个判断是否是空行是空行不执行添加代码。
#5
天上的星2009-08-28 17:17
回复 4楼 yms123
谢谢了,解决了!
1