Data Import - Excel to SQL Azure? [closed]

落爺英雄遲暮 提交于 2019-12-11 08:12:14

问题


Are there any available tools that make importing data from an Excel sheet (or even Access) to SQL Azure easy? I could write a C# script (and I'm assuming that the best available right now) but I thought I'd check in case there were other tools out there. I have as simple Excel sheet to import but its tens-of-thousands of records and would rather do it with an automated tool.

Help?


回答1:


Option 1, Copy and Paste

This a very crude solution but I have used it before, admittedly with smaller volumes of data. Simply select the rows and columns in Excel, making sure they correlate with your database table schema. Copy to the Clipboard. Open up a connection to your database in Visual Studio select the last empty row and paste.

Like I said, a very crude solution but if it works and saves you time that's what matters. Try with a small selection of rows first and don't forget to exclude any auto-incrementing columns. If you convert to CSV first you will nuke any Excel formatting that may not import into your table schema. I have to be honest I don't know how this method will perform with larger datasets, obviously it will depend on the data in the Excel document, number of columns etc. You may need to move the data in chunks but it could well be quicker than other methods.

Option 2, CSV to DataTable

The second method requires some coding but will give you more control over how the data is mapped to the data table. It basically involves converting the document to a CSV from Excel, reading into a DataTable object looping the rows and inserting to the SQL Database table.

Dim dt As DataTable = New DataTable("myData")
Dim DataFile As FileInfo = New FileInfo("c:\myspreadsheet.csv")

Dim MyConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & DataFile.Directory.FullName & "';Extended Properties='text;HDR=NO';Jet OLEDB:Engine Type=96;")
Dim oledataAdapter As OleDbDataAdapter
oledataAdapter = New OleDbDataAdapter("SELECT * FROM [" & DataFile.Name & "]", MyConnection)

oledataAdapter.Fill(dt) 'Bind the csv to the data table

'LOOP AND INSERT HERE...
For Each DataRowObj As DataRow In dt.Rows

Next



回答2:


You can also use SQL Server Import & Export Data (32 bit) to transfer data from an excel file to a table on sql azure. It is extremely fast. Make sure when you choose a destination, it is .Net Framework Data Provider for SqlServer. You will have to set Data Source, User ID, Password & Initial Catalog property as well.



来源:https://stackoverflow.com/questions/15483369/data-import-excel-to-sql-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!