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

Recommended Answers

All 3 Replies

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.

Just guessing, but maybe you need to dispose the data adapter before closing the connection?

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)

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.