[align=left]
asp實現(xiàn)excel導(dǎo)入到sqlserver數(shù)據(jù)庫的實例源碼:
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 編輯過