'ofdImport.Filter = "Excel Files (*.xls)|*.xls" ofdImport.FileName = "" If ofdImport.ShowDialog(Me) = Windows.Forms.DialogResult.Cancel Then Exit Sub End If txtPath.Text = ofdImport.FileName If txtPath.Text <> "" Then chkItemList.Visible = True dgvImportData.Visible = True pnlDataMsg.Visible = False dgvImportData.Columns.Clear() chkItemList.Items.Clear() Try Dim conExcel As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & txtPath.Text & " '; Extended Properties=Excel 8.0;") Dim excelSelect As New OleDbCommand Dim excelAdp As New OleDbDataAdapter Dim excelSchemaDt As DataTable Dim dset As New DataSet If conExcel.State Then conExcel.Close() conExcel.Open() excelSelect.Connection = conExcel excelSchemaDt = conExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) Dim sheetName As String = excelSchemaDt.Rows(0)("TABLE_NAME").ToString() excelSelect.CommandText = "select * from [" & sheetName & "] " excelAdp.SelectCommand = excelSelect excelAdp.TableMappings.Add("Table", "TestTable") excelAdp.Fill(dset) dgvImportData.DataSource = dset.Tables(0) Dim i As Integer Dim q(dgvImportData.Columns.Count()) As String For i = 0 To (dgvImportData.Columns.Count - 1) q(i) = (dgvImportData.Columns(i).HeaderText.ToString()) Next i conExcel.Close() i = 0 Dim a As String = "" 'Dim q(frmImportWizard.gridImport.Columns.Count()) As String For i = 0 To dgvImportData.Columns.Count - 1 a = dgvImportData.Columns(i).HeaderText.ToString() 'CheckedListBox1.Items.Add(a) chkItemList.Items.Add(a) Next i chkAll.Visible = True chkAll.Checked = False lblColumnData.Visible = True Catch ex As Exception 'MsgBox(ex.Message, MsgBoxStyle.Information) End Try End If
Dim conExcel As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & txtPath.Text & "';Extended Properties=""Excel 8.0;HDR=YES;IMEX=1""")
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)