/*************************************************************************/
/* excel数据证书导入程序 */
/* 2003-6-13 yinxiang www.ykce.com */
/*************************************************************************/
/* dataintosqlserver_ceritificate(strfilename,strsheetname,myconn,strkind) */
/* 参数说明: */
/* strfilename –xls文件名 */
/* 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哪一个表签,即表
