asp实现excel导入到sqlserver数据库的实例源码
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
[align=left]
[p]asp实现excel导入到sqlserver数据库的实例源码:[/p] [p]dim conn [br]dim conn2 [br]set conn=createobject("adodb.connection") [br]conn.open "provider=microsoft.jet.oledb.4.0;jet oledb:database password=;data source=c:\book1.mdb" [/p] [p]set conn2=createobject("adodb.connection") [br]conn2.open "provider=microsoft.jet.oledb.4.0;jet oledb:database password=;extended properties=excel 5.0;data source=c:\book1.xls" [/p] [p][br]sql = "select * from [sheet1$]" [br]set rs = conn2.execute(sql) [br]while not rs.eof [br]sql = "insert into xxx([a],[b],[c],[d]) values(’"& fixsql(rs(0)) &"’,’"& fixsql(rs(1)) &"’,’"& fixsql(rs(2)) &"’,’"& fixsql(rs(3)) &"’)" [br]conn.execute(sql) [br]rs.movenext [br]wend [/p] [p]conn.close [br]set conn = nothing [br]conn2.close [br]set conn2 = nothing [/p] [p]function fixsql(str) [br]dim newstr [br]newstr = str [br]if isnull(newstr) then [br]newstr = "" [br]else [br]newstr = replace(newstr,"’","’’") [br]end if [br]fixsql = newstr [br]end function[/p][/align] 该文章在 2010/6/27 17:25:32 编辑过 |
关键字查询
相关文章
正在查询... |