Private Sub Contestant_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim command As String
Dim dsSET As New DataSet
Dim connect As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\athan\Documents\PAGEANT.accdb")
command = "SELECT * from Contestant "
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(command, connect)
comSTR = "SELECT * from Contestant "
dsSET.Clear()
da.Fill(dsSET, "contest")
dgvContestant.DataSource = dsSET
dgvContestant.DataMember = "contest"
End Sub
I don't understand the above code but it still fetches data from the database and load it to datagridview.
Below is another code but throwing this error: 'Command text was not set for the command object.'
Private Sub Contestant_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dsSET As New DataSet
Dim connect As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\athan\Documents\PAGEANT.accdb")
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand
With cmd
.Connection = connect
.CommandText = "SELECT * from Contestant "
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(command, connect)
.Connection.Open()
.ExecuteNonQuery()
da.Fill(dsSET, "contest")
dgvContestant.DataSource = "contest"
.Connection.Close()
End With
End Sub