Dim cn As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=Excel 8.0;")
cn.Open()
Dim da As New OleDbDataAdapter("Select *from[MyExcel$]", cn)
Dim dt As New DataTable
da.Fill(dt)
'กำหนดค่าเริ่มต้นให้กับ datagrideview
With dgvImport
.AllowUserToAddRows = False
.BorderStyle = BorderStyle.None
.DataSource = dt
.Columns(0).HeaderText = "ลำดับ"
.Columns(1).HeaderText = "รหัสนิสิต"
' .Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.Columns(2).HeaderText = "ชื่อนิสิต"
.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.Columns(3).HeaderText = "สาขา"
dt.Dispose()
dt = Nothing
da.Dispose()
da = Nothing
With cn
.Close()
.Dispose()
End With
End With