0

i have some trobles in updating my database. ihave this codes :

Dim cmd As OleDbCommand
        Dim sql As String
        sql = "UPDATE nmat SET nip = '" & lblNipDosen.Text & "', nim = '" & TxtNIM.Text & "', ntugas = '" & TxtNtugas.Text & "', nabsensi = '" & TxtNabsen.Text & "', nuts = '" & TxtNuts.Text & "', nuas = '" & TxtNuas.Text & "' WHERE nim='" & TxtNIM.Text & "'"

        conn.Open()
        Dim reader As OleDbDataReader

        Try
            cmd = New OleDbCommand(sql, conn)
            cmd.ExecuteNonQuery()

            DataGridView1.Refresh()

        Finally
            'reader.Close()
        End Try
        conn.Close()

my problem is, by these code, the grid can be refreshed after i close and open this form again. but if i check in my ms Access, the data was not chanded at all. how to update my database and showed in my datagrid??

Sam
  • 13
  • 1
  • 1
  • 4
  • Are you sure that you are looking at the same database? What is your connection string? – Steve May 07 '13 at 18:17

1 Answers1

0

Try This :

    Dim cmd As OleDbCommand
    Dim rstTable As New DataTable()
            Dim sql As String
            sql = "UPDATE nmat SET nip = '" & lblNipDosen.Text & "', nim = '" & TxtNIM.Text & "', ntugas = '" & TxtNtugas.Text & "', nabsensi = '" & TxtNabsen.Text & "', nuts = '" & TxtNuts.Text & "', nuas = '" & TxtNuas.Text & "' WHERE nim='" & TxtNIM.Text & "'"

            conn.Open()
            Dim reader As OleDbDataReader

            Try
                cmd = New OleDbCommand(sql, conn)
                rstTable.Load(cmd.ExecuteReader())
                DataGridView1.DataSource =rstTable

            Finally
                'reader.Close()
            End Try
            conn.Close()

your gridview columns should have bound to a field

saeed
  • 2,477
  • 2
  • 23
  • 40