登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

樱之花

叶散的时候,你明白欢聚;花谢的时候,你明白青春.

 
 
 

日志

 
 
关于我

分类中“我的实验室”是我在日常工作中的一些知识总结,有些写的比较匆忙,可能大家在阅读时会产生困扰,后期有时间我会重新整理编辑,谢谢大家的到访,您们的支持是我前进的动力!

如何把EXCEL数据导入到SQL SERVER数据库中(ASP)  

2007-03-20 11:32:10|  分类: ASP开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

步骤:
1.先上传
2.建立excel记录集
3.建立sql server数据库记录集
4.读取数据并添加到数据库中
5.清空连接

今天把部分代码整理如下:
Choose.asp
Export_Clothes.asp

Choose.asp部分代码:

<table width="100%" height="250" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td><form method="post" action="Export_Clothes.asp" enctype="multipart/form-data">
      <table width="100%" height="47" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
        <tr>
          <td height="24" bgcolor="#FFFFCC">导入到工作服维护表</td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">选择EXCEL文件:
            <input type="file" /><br /><input type="submit" value="上传" /><input type="hidden" value="exportcloth" /></td>
        </tr>
      </table>
        </form>
<form method="post" action="Export_Clothes.asp" enctype="multipart/form-data">
      <table width="100%" height="47" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
        <tr>
          <td height="24" bgcolor="#FFFFCC">导入到人员信息表</td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">选择EXCEL文件:
            <input type="file" /><br /><input type="submit" value="上传" /><input type="hidden" value="exportusers" /></td>
        </tr>
      </table>
        <br />
        <font color="#FF0000">*</font> 注意:请正确选择相关的EXCEL文件导入。
</form>
    </td>
  </tr>
</table>

Export_Clothes.asp部分代码:

Function ExportUsers
  set file=upload.file("file_users")
  if file.FileSize>0 then
   if GetFileType(file.FileName) <> ".xls" then
    Call ShowMsg("警告:只能上传Excel文件!",0,"")
   end if
   CALL DelFile("../../upload/export_users.xls")
   file.saveAs Server.mappath("../../upload/export_users.xls")
   excconn.Open "Driver={Microsoft Excel Driver (*.xls)};HDR=Yes;DBQ="&Server.MapPath("../../upload/export_users")
   set excrs = excconn.execute("select * from [Sheet1$]")
   myconn.conn.execute("delete from GA_hr_info")
   rs.open "select * from GA_hr_info",MyConn.Conn,1,3

              do while not excrs.EOF
    if excrs(0) <> "" and isnull(excrs(0)) = false then
                  rs.addnew
    rs("taskid") = 0
    rs("hrid") = excrs(0)
    rs("dspname") = replace(excrs(1)," ","")
    rs("dept") = excrs(2)
    rs("joindate") = excrs(3)
    rs("status") = "A"
                  rs.update
    end if
                 excrs.MoveNext
             Loop
   Call ShowMsg("成功:人员数据上传成功!",1,"Choose.asp") 
  else
   Call ShowMsg("警告:请不要上传空文件!",0,"")
  end if
 End Function

  评论这张
 
阅读(1485)| 评论(2)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018