热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->asp 
站内搜索:
将Excel中的数据导入至MsSQLSERVER中(示例)
作者:wan 来源:不详 整理日期:2007-3-23

dataIntoSqlServer_ceritificate(strFileName,strSheetName,myConn,strKind) */

sub dataIntoSqlServer_ceritificate(strFileName,strSheetName,myConn,strKind)
定义
dim myConnection
dim strName
dim rsXsl,rsSql
dim str_Xsl,str_Sql
dim myConn_Xsl
dim cmd
dim i,j
dim strKmId 科目ID号
dim maxId
dim maxOrderId
dim maxKm
dim str_Date
dim str_Kind

strName=strFileName
set myConnection=server.createobject("adodb.connection")
set rsXsl=Server.Createobject("ADODB.Recordset")
set rsSql=Server.CreateObject("ADODB.Recordset")
set cmd=Server.CreateObject("ADODB.Command")
set cmd.ActiveConnection=myConn

证书种类
str_Kind=split(strKind,"-")

加入上传日期时间
str_Date=FormatDateTime(Date(),2)& " " & Time()
myConn_Xsl="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strName& ";Extended Properties=Excel 8.0"
打开连接
myconnection.open myConn_Xsl

打开表
str_Xsl="select * from ["& strSheetName &"$]"
rsXsl.open str_Xsl,myconnection,1,1

//姓名,身份证号码,证书号码,签发日期,有效日期
j=1
Do While not rsXsl.eof


取出最大值
str_Sql="select Max(id) as maxId from ceritificate"
rsSql.open str_Sql,myConn,1,3
If Not rsSql.Eof Then
If not isNull(rsSql("maxId")) Then
maxId=Clng(rsSql("maxId"))+1
Else
maxId=1
End if
else
maxId=1
End if
rsSql.close//关闭对象
加入成绩单
str_Sql=" insert into ceritificate values("&maxId&","&rsXsl(0)&","&rsXsl(1)&","&rsXsl(2)&","& str_Kind(0) & "," & rsXsl(3)& ","&rsXsl(4) &"," & str_Date &")"
cmd.CommandText=str_Sql
cmd.Execute()

j=j+1
rsXsl.movenext
Loop

response.write "<font color=red>" & str_Kind(1) & "</font>证书导入成功.<br>"
response.write "共导入<font color=red>" & j & "</font>条证书信息.<br>"
response.write "<a href=# onclick=self.close();>关闭窗口</a>"
set rsXsl=nothing
set rsSql=nothing
set myconnection=nothing
set cmd=nothing
end sub

代码说明:
  1)上列代码是将EXCEL中的数据信息导入至SQLSERVER中,strKind参数是指证书的种类;
2) 链接Excel字符串:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strName& ";Extended Properties=Excel 8.0"
3) str_Xsl="select * from ["& strSheetName &"$]"这条语句是确定是Excel哪一个表签,即表

相关文章