Imports System.Data.Common Imports System.Data.SqlClient Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fname As String Using ofd As New OpenFileDialog If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then fname = ofd.FileName End If End Using Dim olecon As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;Data Source=" & fname & ";Extended Properties=""Excel 12.0;IMEX=1;HDR=YES;""" Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(olecon) dBaseConnection.Open() SSQL = "select [LOT],[IMAGE],[STYLENO],[VENDOR] from [Sheet1$]" Dim cmd As New OleDbCommand(SSQL, dBaseConnection) Dim da As New OleDbDataAdapter(cmd) Dim ds As New DataSet da.Fill(ds) Using dr As DbDataReader = cmd.ExecuteReader If SHCONNECTION.State = ConnectionState.Closed Then Call SHconn(MCONNECTIONSTRING) End If Using bulkCopy As New SqlBulkCopy(MCONNECTIONSTRING) bulkCopy.DestinationTableName = "DBimage" bulkCopy.WriteToServer(ds) End Using End Using End Sub End Class
source share