用程式將excel匯入SQL 如何覆蓋或更新SQL舊有table?- 藍色小舖 BlueShop

用程式將excel匯入SQL 如何覆蓋或更新SQL舊有table?- 藍色小舖 BlueShop

1 Dim excelConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\test.xls;Extended Properties=Excel 12.0;")


2 excelConnection.Open()

3 Dim excelCommand As New OleDbCommand("SELECT * INTO [ODBC; Driver={SQL Server};Server=我的server;Database=我的資料庫;User Id=XXX;Password=;Integrated Security=SSPI].[資料表名稱] FROM [資料表名稱];", excelConnection)

4 Try

5 excelCommand.ExecuteNonQuery()

6 Console.WriteLine("success")

7 Catch ex As Exception

8 Console.WriteLine("fail")

9 End Try

留言

這個網誌中的熱門文章