Hello, im working on a project that works with an access database but i dont know how to edit an existing record...

here is the code that i use for reading the database:

Public Function ask()

        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        con.Open()
        Dim da As New OleDbDataAdapter("select * from data", con)
        da.Fill(dt)
        Dim newRow As DataRow = dt.NewRow
        For Each DataRow In dt.Rows

            If CardID.Text = DataRow.Item(0) Then
                usrname = DataRow.Item(1)
                cardv = DataRow.Item(0)
                usrid = DataRow.Item(2)

                log2.DataSource = dt.DefaultView
                DataRow.Item("card") = cardv
                'dt.Rows.Add(newRow)
                Dim cb As New OleDbCommandBuilder(da)
                log.DataSource = dt.DefaultView
                da.Update(dt)

                Return True
            Else

            End If
        Next

        con.Close()





        Return False


        
    End Function

Here is the code i used to add a new record:

con.Open()
        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim da As New OleDbDataAdapter("select * from data", con)
        da.Fill(dt)

        Dim newRow As DataRow = dt.NewRow
        With newRow
            .Item("card") = cardtxt.Text
            .Item("name") = nametxt.Text
            .Item("id") = idtxt.Text
            .Item("in") = ComboBox1.Text
        End With
        dt.Rows.Add(newRow)
        Dim cb As New OleDbCommandBuilder(da)
        da.Update(dt)
        DataGridView1.DataSource = dt.DefaultView
        con.Close()
        cardtxt.Clear()
        nametxt.Clear()
        idtxt.Clear()
        cardtxt.Select()

now, both of those codes work just fine(I know you will say there is an easier way to use access, but trust me, i need it this way).

So how could i edit an existing record?

It looks like you already know about

Dim cb As New OleDbCommandBuilder(da)
        da.Update(dt)

What seems to be the problem?

It looks like you already know about

Dim cb As New OleDbCommandBuilder(da)
        da.Update(dt)

What seems to be the problem?

there is no problem, i just want to know how to edit a certain record:

for example i want it to find the record where DataRow.Item(0) is "123" then it it change the record's DataRow.Item(0) to "321"

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.