网络软件 系统工具 应用软件 图形图像 多媒体类 免费游戏 安全相关 免费音乐 网页素材 电子书籍 考试考题 建站源码
教育教学 多媒体类 编程开发 操作系统 游戏天地 娱乐天地 简历求职 站长专区 网页设计 安全技术 图形图像 文学驿站
业界资讯 | 图形图像 | 操作系统 | 网络冲浪 | 工具软件 | 办公软件 | 媒体动画 | 精文荟萃 | 认证考试 | 网页设计 | 技术开发 | 专栏
当前位置:热点网络学院办公软件Excel将Excel中的数据导入至MsSQLSERVER中示例
精品推荐
热点TOP10
·真的好轻松 Execl XP数据统计全攻略
·Office超级技巧连载─Excel工作簿技巧
·Excel模板实用技巧五则
·Excel实用操作技巧九则
·巧用Excel函数来实现工作表间的数据关联
·Excel XP“单元格”合并与拆分的技巧
·让Excel 2000自动计算数据
·巧用Excel:利用身份证号码 提取个人信息
·学十条小经验 Excel文档打印得心应手
·Excel妙用-公式结果我都要
·EXCEL2000使用技巧十招
·用Excel宏命令快速处理学生成绩
·在Excel单元格中设置“斜线”效果
·Excel2007中插入页眉和页脚超简单
·Excel 2000暗藏的赛车游戏
·用Excel生成九九乘法表
·Excel中设置字符上、下标的方法
·Excel单元格内容、行列、工作表的隐藏方法
·技巧:Excel中日期与时间的快速处理
·教你让Excel中人名显示更美观的技巧
将Excel中的数据导入至MsSQLSERVER中示例
日期:2005年7月25日 作者:热点网络学院 查看:[大字体 中字体 小字体]

'/*************************************************************************/
'/* 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哪一个表签,即表

(出处:http://www.vipcn.com

关于我们 | 帮助(?) | 版权声明 | 友情连接 
Copyright 2005-2005 viphot.com All Rights Reserved.
Powered by:mesky