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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |