这段是批量将Excel数据写入数据库的,但是关闭程序后程序怎么还会在后台运行的?是连接没关闭吗?
For ii = 0 To ListBox1.Items.Count - 1
fileName = ListBox1.Items.Item(ii)
Dim ExcelConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" & fileName & "'; Extended Properties=""Excel 12.0 Xml; HDR=Yes""")
ExcelConnection.Open()
Dim expr As String = "SELECT [PASS_ID] FROM [拆分明细$]"
Dim objCmdSelect As OleDbCommand = New OleDbCommand(expr, ExcelConnection)
Dim objDR As OleDbDataReader
Dim SQLconn As New SqlConnection()
Dim ConnString As String = "server=localhost;database=STdata;user id=sa;password=Nngs8888!"
SQLconn.ConnectionString = ConnString
SQLconn.Open()
Using bulkCopy As New SqlBulkCopy(SQLconn)
bulkCopy.DestinationTableName = "chaifen"
Try
objDR = objCmdSelect.ExecuteReader
bulkCopy.WriteToServer(objDR)
SQLconn.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Using
ExcelConnection.Close()
ProgressBar1.Value = ii
Next