Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Import Excel to SQL 2005

Status
Not open for further replies.

weldrick

Technical User
Jun 8, 2006
3
CA
Hi,
I'm using the following VB code from Microsoft web site to import an excel sheet to SQL 2005. If I run it for the first time, there is no error, but no table is created in SQL server. If I run it for second time, it gives me a run-time error: Table 'test' already exists. But this table does not exist. If I change the table name, it runs once and running for second time generates the same error.

Any idea, solution, advice is highly appreciated.

Dim cn As adodb.Connection
Dim strSQL As String
Dim lngRecsAff As Long
Set cn = New adodb.Connection
cn.Open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties=""Excel 8.0;HDR=YES"""

strSQL = "SELECT * INTO DSN=mts_test;Uid=mts_test;Pwd=mts_test].test FROM [Sheet1$]"

cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
cn.Close
Set cn = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top