asp实现excel导入到sqlserver数据库的实例源码
|
admin
2010年6月27日 17:25
本文热度 6517
|
[align=left]
asp实现excel导入到sqlserver数据库的实例源码:
dim conn
dim conn2
set conn=createobject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;jet oledb:database password=;data source=c:\book1.mdb"
set conn2=createobject("adodb.connection")
conn2.open "provider=microsoft.jet.oledb.4.0;jet oledb:database password=;extended properties=excel 5.0;data source=c:\book1.xls"
sql = "select * from [sheet1$]"
set rs = conn2.execute(sql)
while not rs.eof
sql = "insert into xxx([a],,[c],[d]) values(’"& fixsql(rs(0)) &"’,’"& fixsql(rs(1)) &"’,’"& fixsql(rs(2)) &"’,’"& fixsql(rs(3)) &"’)"
conn.execute(sql)
rs.movenext
wend
conn.close
set conn = nothing
conn2.close
set conn2 = nothing
function fixsql(str)
dim newstr
newstr = str
if isnull(newstr) then
newstr = ""
else
newstr = replace(newstr,"’","’’")
end if
fixsql = newstr
end function
[/align]
该文章在 2010/6/27 17:25:32 编辑过