i got problem to refresh my database when :
save= i already save but need to restart vb to find that data again.
delete= when i delete and try back to menu then find that data, the data not delete yet..same with save need to restart vb.net then the data gone

what i should put in my coding..?

this for my save coding.

Imports System.Data

Public Class frmANGGARANBARU

    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sqlPelan, sqlPremium, sqlRekodAnggaran As String

    Private Sub frmANGGARANBARU_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'SISTEM_DATABASEDataSet.KadarPremium' table. You can move, or remove it, as needed.
        Me.KadarPremiumTableAdapter.Fill(Me.SISTEM_DATABASEDataSet.KadarPremium)
        'TODO: This line of code loads data into the 'SISTEM_DATABASEDataSet.PelanFaedah' table. You can move, or remove it, as needed.
        Me.PelanFaedahTableAdapter.Fill(Me.SISTEM_DATABASEDataSet.PelanFaedah)


        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = H:\PROJEK\New Sistem\SISTEM_DATABASE.mdb"
        con.Open()

        sqlPelan = "SELECT * FROM PelanFaedah"
        da = New OleDb.OleDbDataAdapter(sqlPelan, con)
        da.Fill(ds, "PelanFaedah")

        sqlPremium = "SELECT * FROM KadarPremium"
        da = New OleDb.OleDbDataAdapter(sqlPremium, con)
        da.Fill(ds, "KadarPremium")

        sqlRekodAnggaran = "SELECT * FROM RekodAnggaran"
        da = New OleDb.OleDbDataAdapter(sqlRekodAnggaran, con)
        da.Fill(ds, "RekodAnggaran")

        con.Close()

        cmbPelan.Text = ""
        cmbPremium.Text = ""
        cmbJPembayaran.Text = ""

        cmbJPembayaran.Items.Add("Bulanan")
        cmbJPembayaran.Items.Add("3 Bulan")
        cmbJPembayaran.Items.Add("6 Bulan")

    End Sub
    Private Sub OutputPremium()
        With ds.Tables("KadarPremium").Rows(cmbPremium.SelectedIndex)
            Select Case cmbPelan.Text
                Case (1)
                    lblPremium.Text = .Item("20TP1")
                Case (2)
                    lblPremium.Text = .Item("20TP2")
                Case (3)
                    lblPremium.Text = .Item("20TP3")
                Case (4)
                    lblPremium.Text = .Item("20TP4")
                Case (5)
                    lblPremium.Text = .Item("20TP5")
                Case (6)
                    lblPremium.Text = .Item("20TP6")
                Case (7)
                    lblPremium.Text = .Item("20TP7")
                Case Else
                    'whatever you want to do here
            End Select

            If cmbJPembayaran.Text = "Bulanan" Then
                lblPremiumJP.Text = lblPremium.Text \ 12
            ElseIf cmbJPembayaran.Text = "3 Bulan" Then
                lblPremiumJP.Text = (lblPremium.Text \ 12) * 3
            ElseIf cmbJPembayaran.Text = "6 Bulan" Then
                lblPremiumJP.Text = lblPremium.Text \ 2
            Else
                'whatever
            End If
        End With
    End Sub

    Private Sub cmbPelan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPelan.SelectedIndexChanged

        txtKHUKK.Text = ds.Tables("PelanFaedah").Rows(cmbPelan.SelectedIndex).Item("KHUKK")
        txt36P.Text = ds.Tables("PelanFaedah").Rows(cmbPelan.SelectedIndex).Item("36P")
        txtPHH.Text = ds.Tables("PelanFaedah").Rows(cmbPelan.SelectedIndex).Item("PHH")
        txtPKKAAK.Text = ds.Tables("PelanFaedah").Rows(cmbPelan.SelectedIndex).Item("PKKAAK")
    End Sub

    Private Sub cmbPremium_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPremium.SelectedIndexChanged
        OutputPremium()
    End Sub

    Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click
        btnSimpan.Enabled = True
        btnBaru.Enabled = False
        btnSemula.Enabled = True

        txtNama.Clear()
        txtNoIC.Clear()
        txtTarikhLahir.Clear()
        txtTarikhMI.Clear()
        txtAlamat.Clear()
        txtNoTelefon.Clear()
        cmbPremium.Text = ""
        cmbPelan.Text = ""
        lblPremium.Text = ""
        cmbJPembayaran.Text = ""
        txtKHUKK.Text = ""
        txt36P.Text = ""
        txtPHH.Text = ""
        txtPKKAAK.Text = ""
        lblPremiumJP.Text = ""

    End Sub

    Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim dsNewRow As DataRow

        dsNewRow = ds.Tables("RekodAnggaran").NewRow()
        dsNewRow.Item("Nama") = txtNama.Text
        dsNewRow.Item("NoIC") = txtNoIC.Text
        dsNewRow.Item("Umur") = cmbPremium.Text
        dsNewRow.Item("Alamat") = txtAlamat.Text
        dsNewRow.Item("TarikhLahir") = txtTarikhLahir.Text
        dsNewRow.Item("TarikhMI") = txtTarikhMI.Text
        dsNewRow.Item("Pelan") = cmbPelan.Text
        dsNewRow.Item("NoTelefon") = txtNoTelefon.Text
        dsNewRow.Item("JPembayaran") = cmbJPembayaran.Text
        dsNewRow.Item("PremiumTahunan") = lblPremium.Text
        dsNewRow.Item("PremiumJP") = lblPremiumJP.Text
        ds.Tables("RekodAnggaran").Rows.Add(dsNewRow)
        da.Update(ds, "RekodAnggaran")
        MsgBox("Rekod Anggaran Telah Disimpan")
        btnSimpan.Enabled = False
        btnBaru.Enabled = True
        btnSemula.Enabled = True

    End Sub

this for find/search data coding.

Private Sub btnCari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCari.Click

        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")
        End If

    End Sub

this for delete coding.

Private Sub btnPadam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPadam.Click


        If (txtNoIC.Text = "") Then
            MsgBox("Cari rekod terlebih dahulu.")
            ' da1 = New SqlDataAdapter("select * from sto where icode=" & txticode.Text, con)
            ' da1.Fill(ds1)
        Else '(txticode.Text <> "") 

            sql = ("DELETE * FROM RekodAnggaran WHERE [NoIC]='" & txtNoIC.Text & "'")
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds)

            txtNama.Clear()
            txtNoIC.Clear()
            txtTarikhLahir.Clear()
            txtTarikhMI.Clear()
            txtAlamat.Clear()
            txtNoTelefon.Clear()
            cmbPremium.Text = ""
            cmbPelan.Text = ""
            cmbJPembayaran.Text = ""
            lblPremium.Text = ""
            lblPremiumJP.Text = ""

            MsgBox("Rekod berjaya dipadam.")
            da.Update(ds, "RekodAnggaran")


        End If
    End Sub

Pouplate grid, combo or any other list control immediately after a record has been deleted , added or updated.

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