I have written the code below to read data from an Excel sheet and display data in a combobox in Visual Basic.
However, when I click "run" nothing is displayed.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim MyConnection As New OleDb.OleDbConnection
Dim MyCommand As New OleDb.OleDbCommand
Dim filePath, sql As String
filePath = "C:\Users\Nour\Desktop\projects\grade10\grade10\atlas.xlsx"
sql = "Select continent from [Sheet1]"
MyConnection.ConnectionString = $"Provider= Microsoft.Jet._OLEDB 11.0;data source = {filePath};Extended_Properties=Excel 8.0"
MyConnection.Open()
MyCommand.Connection = MyConnection
MyCommand.CommandText = sql
Dim da As New OleDb.OleDbDataAdapter
da.SelectCommand = MyCommand
Dim dt As New DataTable
da.Fill(dt)
Me.ComboBox1.DataSource = dt
Me.ComboBox1.DisplayMember = dt.Columns(0).ToString
MyConnection.Close()