Imports System.Data

Public Class Section
    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As New OleDb.OleDbDataAdapter
    Dim dv As New DataView
    Dim inc As Integer
    Dim maxrows As Integer
    Dim cmd As OleDb.OleDbCommand


    Dim constr As String

    Private Sub Section_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Records.mdb;Persist Security Info=True;Jet OLEDB:Database Password=registerme"
        con.Open()
        constr = "select * from Sections"
        da = New OleDb.OleDbDataAdapter(constr, con)
        da.Fill(ds, "Sections")
        dv.Table = ds.Tables("Sections")
        con.Close()
        Me.DataGridView1.DataSource = dv
        maxrows = ds.Tables("Sections").Rows.Count
        ' inc = -1

    End Sub

    Private Sub NavigateRecords()
        txtUpdate.Text = ds.Tables("Sections").Rows(inc).Item(1)


'code for update
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
       
        ds.Tables("Sections").Rows(inc).Item(1) = txtUpdate
        da.Update(ds, "Sections")

        MsgBox("Data Updated")

Hi!

Your update should be done like this:

//==========To Update
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Records.mdb;Persist Security Info=True;Jet OLEDB:Database Password=registerme"
        con.Open()
        constr = "Update TableName SET ColumnToSet=" & AnyValue & "YourPrimaryKey=" & anyValue"
        cmd =New OleDb.OleDbCommand(constr,con)
        cmd.ExecuteNonQuery()
//===============To re-bind after Update
        constr = "select * from Sections"
        da = New OleDb.OleDbDataAdapter(constr, con)
        da.Fill(ds, "Sections")
        dv.Table = ds.Tables("Sections")
        con.Close()
        Me.DataGridView1.DataSource = dv

For update, you can follow this link as well:
http://www.codeproject.com/KB/vb/InsertUpdateDeleteSearch.aspx

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.