What mean that error?
can someone help me?


The connection was not closed. The connection's current state is open

Private Sub btnCari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCari.Click
        
        con.Open()
        sql = ("SELECT * FROM RekodAnggaran WHERE [NoIC]='" & txtNoIC.Text & "'")
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "RekodAnggaran")

        If ds.Tables("RekodAnggaran").Rows.Count < 1 Then
            MsgBox("Nombor IC yang dimasukkan tiada didalam rekod.")
            txtNoIC.Clear()
        Else
            txtNama.Text() = ds.Tables("RekodAnggaran").Rows(0).Item("Nama")
            cmbPremium.Text = ds.Tables("RekodAnggaran").Rows(0).Item("Umur")
            txtAlamat.Text = ds.Tables("RekodAnggaran").Rows(0).Item("Alamat")
            txtTarikhLahir.Text = ds.Tables("RekodAnggaran").Rows(0).Item("TarikhLahir")
            txtTarikhMI.Text = ds.Tables("RekodAnggaran").Rows(0).Item("TarikhMI")
            cmbPelan.Text = ds.Tables("RekodAnggaran").Rows(0).Item("Pelan")
            txtNoTelefon.Text = ds.Tables("RekodAnggaran").Rows(0).Item("NoTelefon")
            cmbJPembayaran.Text = ds.Tables("RekodAnggaran").Rows(0).Item("JPembayaran")
            lblPremium.Text = ds.Tables("RekodAnggaran").Rows(0).Item("PremiumTahunan")
            lblPremiumJP.Text = ds.Tables("RekodAnggaran").Rows(0).Item("PremiumJP")
            Return
        End If
        con.Close()

    End Sub

That means exactly what is says, probably there is a piece of code that is executed before this method and you leave the connection open. make sure you close the connection on that method. usually i forgot to close the connection if i use a data reader and then i have this problem.

In what Line it give this error?

Check if you declare the variable for DataReader twice (once as public and once a local in another place)

This article has been dead for over six months. Start a new discussion instead.