尝试一下
MyCommand = New System.Data.OleDb.OleDbDataAdapter("SELECT [Area Code],[Metropolian Area],[Annual Fixed Cost],[Wage per hour] FROM [Candidates Call Center Location$]",MyConnection)
,
Imports System.Data.OleDb
Imports System.IO
Imports System.Data.DataTable
Public Class Welcome
Private Sub ImportExceldata(DataExcelFile As String,ImportData As DataGridView)
If ComboBox1.SelectedIndex.Equals(0) Then
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim dataSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & DataExcelFile & "';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [CandidatesCallCenterLocation$]",MyConnection)
'MyCommand.TableMappings.Add("Table","Attendace")
dataSet = New System.Data.DataSet
MyCommand.Fill(dataSet)
ImportData.DataSource = dataSet.Tables(0)
DataGridView.DataSource = dataSet.Tables(0)
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
ElseIf ComboBox1.SelectedIndex.Equals(1) Then
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim dataSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & DataExcelFile & "';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [ExpectedNumberofCalls$]","Attendace")
dataSet = New System.Data.DataSet
MyCommand.Fill(dataSet)
ImportData.DataSource = dataSet.Tables(0)
DataGridView.DataSource = dataSet.Tables(0)
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
ElseIf ComboBox1.SelectedIndex.Equals(2) Then
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim dataSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & DataExcelFile & "';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [CostProcessingTelephoneCalls$]","Attendace")
dataSet = New System.Data.DataSet
MyCommand.Fill(dataSet)
ImportData.DataSource = dataSet.Tables(0)
DataGridView.DataSource = dataSet.Tables(0)
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End If
End Sub
Private Sub Button1_Click(sender As Object,e As EventArgs)
End Sub
Private Sub ComboBox_SelectedIndexChanged(sender As Object,e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ImportExceldata("C:\Users\Home\Desktop\dss.xlsx",DataGridView)
End Sub
End Class
本文链接:https://www.f2er.com/3154366.html