Private Sub continueimprtBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles continueimprtBTN.Click
'IMPORT DATA FROM EXCEL INTO SQL DB MODULE TABLE
'CONNECTION STRING TO EXCEL WORKBOOK
Dim excelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Adam\Desktop\easydata.xls;Extended Properties=""Excel 8.0;HDR=YES;"""
'CREATE CONNECTION TO EXCEL WORKBOOK
Using connection As OleDbConnection = New OleDbConnection(excelConnectionString)
Dim myCommand As New OleDbCommand("SELECT * FROM [Sheet1$]", connection)
connection.Open()
'CREATE DbDataReader TO DATA WORKSHEET
Using dr As OleDbDataReader = myCommand.ExecuteReader()
'BULK COPY TO SQL SERVER
Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(MySharedConnExisting)
bulkCopy.DestinationTableName = "dbo." & moduletableCB.Text
bulkCopy.WriteToServer(dr)
End Using
End Using
If MySharedConnExisting.State = ConnectionState.Open Then
MySharedConnExisting.Close()
End If
End Using
End Sub
|