Hi Im having an error with my app, Im still learning to code.
It gives me error at line rs = cmdOLEDB.ExecuteReader
Here's my full code

Imports System.Data
Imports System.Data.OleDb
Imports System.IO

Public Class Form11
Dim cnnOLEDB As New OleDbConnection
Dim cmdOLEDB As New OleDbCommand
Dim cmdInsert As New OleDbCommand
Dim cmdUpdate As New OleDbCommand
Dim cmdDelete As New OleDbCommand
Dim strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
        System.Environment.CurrentDirectory & "\Akademik.accdb"
Public ADP As OleDbDataAdapter
Public DS As New DataSet

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub Form11_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    cnnOLEDB.ConnectionString = strConnectionString
    cnnOLEDB.Open()
    TampilData()
    tampilcomboboxkelas()
    tampilcomboboxKode_MK()
    tampilcomboboxDosen()
    disableTeksbox()
    ListBox1.Visible = False
End Sub
Sub TampilDataJadwalSesuaiHaridanKelas()
    ADP = New OleDbDataAdapter("SELECT a.Hari,a.Jam,c.Nama_MK, b.Nama_Dosen, a.Ruang , a.kelas from(Jadwal a left Join Master_Dosen b ON b.NIP=a.NIP) LEFT JOIN Master_MK c ON c.Kode_MK=a.Kode_MK where a.Hari = '" & CmbHari.Text & "' AND a.Kelas= '" & CmbKelas.Text & "' order by a.Jam ASC", cnnOLEDB)
    DS = New DataSet
    ADP.Fill(DS, "Tabel1")
    DataGridView1.DataSource = DS.Tables("Tabel1")
End Sub
Sub bersih()
    TxtTA.Text = ""
    TxtJam.Text = ""
    CmbMK.Text = ""
    TxtRuang.Text = ""
    CmbHari.Text = ""
    CmbKelas.Text = ""
    TxtNIP.Text = ""
    CmbDosen.Text = ""
    CmbSemester.Text = ""
End Sub
Sub disableTeksbox()
    TxtNIP.Enabled = False
    CMBMK.Enabled = False
End Sub
Sub TampilData()
    ADP = New OleDbDataAdapter("SELECT a.Hari,a.Jam,c.Nama_MK, b.Nama_Dosen, a.Ruang from(Jadwal a left Join Master_Dosen b ON b.NIP=a.NIP) LEFT JOIN Master_MK c ON c.Kode_MK=a.Kode_MK order by a.Hari ASC", cnnOLEDB)
    ADP = New OleDbDataAdapter("SELECT * from Jadwal", cnnOLEDB)
    DS = New DataSet
    ADP.Fill(DS, "Tabel1")
    DataGridView1.DataSource = DS.Tables("Tabel1")
End Sub
Sub tampilcomboboxKode_MK()
    Dim query As String
    Dim rs As OleDbDataReader
    query = "Select Nama_MK from Master_MK "
    cmdOLEDB = New OleDb.OleDbCommand(query, cnnOLEDB)
    rs = cmdOLEDB.ExecuteReader
    Try
        While rs.Read
            CmbMK.Items.Add(rs("Nama_MK"))
        End While
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
    CmbMK.SelectedIndex = 0
    rs.Close()
End Sub
Sub tampilcomboboxkelas()
    Dim query As String
    Dim rs As OleDbDataReader
    query = "Select DISTINCT Kelas  from Kelas "
    ADP = New OleDbDataAdapter(query, cnnOLEDB)
    rs = cmdOLEDB.ExecuteReader
    Try
        While rs.Read
            CmbKelas.Items.Add(rs("Kelas"))
        End While
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
    CmbKelas.SelectedIndex = 0
    rs.Close()
End Sub
Sub tampilcomboboxDosen()
    Dim query As String
    Dim rs As OleDbDataReader
    query = "Select Nama_Dosen from Master_Dosen "
    cmdOLEDB = New OleDb.OleDbCommand(query, cnnOLEDB)
    rs = cmdOLEDB.ExecuteReader
    Try
        While rs.Read
            CmbDosen.Items.Add(rs("Nama_Dosen"))
        End While
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
    CmbDosen.SelectedIndex = 0
    rs.Close()
End Sub
Sub TampilKdMK()
    ListBox1.Visible = False
    ADP = New OleDbDataAdapter("SELECT Kode_MK From Master_MK where Nama_MK = '" & CmbMK.Text & "'", cnnOLEDB)
    DS = New DataSet
    ADP.Fill(DS, "Nama")
    Dim Dta As DataTable = DS.Tables("Nama")
    ListBox1.DataSource = Dta
    ListBox1.DisplayMember = "Kode_MK"
    CmbMK.Text = ListBox1.Text
    ListBox1.Text = ""
End Sub
Sub TampilNIP()
    ListBox1.Visible = False
    ADP = New OleDbDataAdapter("SELECT NIP From Master_Dosen where Nama_Dosen = '" & CmbDosen.Text & "'", cnnOLEDB)
    DS = New DataSet
    ADP.Fill(DS, "Nama")
    Dim Dta As DataTable = DS.Tables("Nama")
    ListBox1.DataSource = Dta
    ListBox1.DisplayMember = "NIP"
    TxtNIP.Text = ListBox1.Text
    ListBox1.Text = ""
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    Me.Dispose()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
        cmdInsert.CommandText = "INSERT INTO Jadwal (Semester, Tahun_Akademik, Hari, Jam, Kelas, Kode_MK, NIP, Ruang)" & _
            "Values(@Semester, @ThnAkad, @Hari, @Jam, @Kelas, @KodeMK, @NIP, @Ruang)"
        cmdInsert.Parameters.AddWithValue("@Semester", Me.CmbSemester.Text)
        cmdInsert.Parameters.AddWithValue("@ThnAkad", Me.TxtTA.Text)
        cmdInsert.Parameters.AddWithValue("@Hari", Me.CmbHari.Text)
        cmdInsert.Parameters.AddWithValue("@Jam", Me.TxtJam.Text)
        cmdInsert.Parameters.AddWithValue("@Kelas", Me.CmbKelas.Text)
        cmdInsert.Parameters.AddWithValue("@KodeMK", Me.CmbMK.Text)
        cmdInsert.Parameters.AddWithValue("@NIP", Me.TxtNIP.Text)
        cmdInsert.Parameters.AddWithValue("@Ruang", Me.TxtRuang.Text)
        cmdInsert.CommandType = CommandType.Text
        cmdInsert.Connection = cnnOLEDB
        cmdInsert.ExecuteNonQuery()
        MsgBox("Record Inserted")
        TampilDataJadwalSesuaiHaridanKelas()
        cmdInsert.Dispose()
        TxtJam.Focus()
        TampilData()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Try
        cmdUpdate.Parameters.AddWithValue("@Semester", Me.CmbSemester.Text)
        cmdUpdate.Parameters.AddWithValue("@ThnAkad", Me.TxtTA.Text)
        cmdUpdate.Parameters.AddWithValue("@Hari", Me.CmbHari.Text)
        cmdUpdate.Parameters.AddWithValue("@Jam", Me.TxtJam.Text)
        cmdUpdate.Parameters.AddWithValue("@Kelas", Me.CmbKelas.Text)
        cmdUpdate.Parameters.AddWithValue("@KodeMK", Me.CmbMK.Text)
        cmdUpdate.Parameters.AddWithValue("@NIP", Me.TxtNIP.Text)
        cmdUpdate.Parameters.AddWithValue("@Ruang", Me.TxtRuang.Text)
        cmdUpdate.Parameters.AddWithValue("@id", Me.CmbHari2.Text)

        cmdUpdate.CommandText = "UPDATE Jadwal SET Semester=@Semester, Tahun_Akademik=@ThnAkad, Hari=@Hari, Jam-@Jam, Kelas=@Kelas, Kode_MK=@KodeMK, NIP=@NIP, Ruang=@Ruang WHERE id=@id"
        cmdUpdate.CommandType = CommandType.Text
        cmdUpdate.Connection = cnnOLEDB
        cmdUpdate.ExecuteNonQuery()
        MsgBox("Record Updated")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim konfirmasi
    konfirmasi = MsgBox("Data Akan di Hapus ?", vbOKCancel, "Hapus Data")
    If konfirmasi = vbOK Then
        If Label12.Text <> "" Then
            Try
                cmdDelete.CommandText = "DELETE FROM Jadwal WHERE id=@id"
                cmdDelete.Parameters.AddWithValue("@id", Me.CmbHari2.Text)
                cmdDelete.CommandType = CommandType.Text
                cmdDelete.Connection = cnnOLEDB
                cmdDelete.ExecuteNonQuery()
                MsgBox("Record Deleted")
                TampilDataJadwalSesuaiHaridanKelas()

            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        Else
            MsgBox("Data tidak ada")
        End If
        cmdDelete.Dispose()
    ElseIf konfirmasi = vbCancel Then
        MsgBox("Data ga jadi di hapus", vbInformation, "Batal")
    End If
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    Dim Hari As Object = DataGridView1.Rows(e.RowIndex).Cells(0).Value
    Dim Jam As Object = DataGridView1.Rows(e.RowIndex).Cells(1).Value
    Dim NamaMK As Object = DataGridView1.Rows(e.RowIndex).Cells(2).Value
    Dim NamaDosen As Object = DataGridView1.Rows(e.RowIndex).Cells(3).Value
    Dim Ruang As Object = DataGridView1.Rows(e.RowIndex).Cells(4).Value
    Dim Kelas As Object = DataGridView1.Rows(e.RowIndex).Cells(5).Value
    CmbSemester.Text = DS.Tables("Tabel1").Rows(e.RowIndex).Item(0).ToString
    TxtTA.Text = DS.Tables("Tabel1").Rows(e.RowIndex).Item(1).ToString
    Label12.Text = DS.Tables("Tabel1").Rows(e.RowIndex).Item(8).ToString
    CmbHari.Text = CType(Hari, String)
    TxtJam.Text = CType(Jam, String)
    CmbMK.Text = CType(NamaMK, String)
    CmbDosen.Text = CType(NamaDosen, String)
    TxtRuang.Text = CType(Ruang, String)
    CmbKelas.Text = CType(Kelas, String)
End Sub
End Class

Thanks!

Change ADP = New OleDbDataAdapter(query, cnnOLEDB) with cmdOLEDB = New OleDb.OleDbCommand(query, cnnOLEDB) at the line no 78. without initializing command object u canot use it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.