ASP implementation to import Excel tables into SQL database

Source: Internet
Author: User
Tags sql access database access

Like an Access database, open an Excel file, read it, and write it in Access if you want to write to SQL Server, change the writing process.

Here's the code:
Dim conn
Dim conn2
Set Conn=createobject ("ADODB. Connection ")
Conn. Open "Provider=Microsoft.Jet.OLEDB.4.0; Jet oledb:database password=;D ata 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],[b],[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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.