none
After clicking in Database Access with "Copy If Newer", How to changes this modified into MS Access Database

    Question

  • Firstly , Thank you so much for your reply

    After obtaining the feedback from KarenInstructor and Cherry Bu, I have follow this instruction.

    The output have only run well on this grid with VB.net, but in preview dataadapter and MS access, there is not change against the updated database.

    Please tell me how to keep this modified datagridview into MS Access ?

    God Bless All Of Us

    Thursday, April 27, 2017 3:14 AM

All replies

  • Hi Muljanto,

    According to your description, you want to modify some data in the DataGridView, and save these changes to the Access. I suggest you to use OleDbCommandBuilder class to achieve it.

    I put one Button and DataGridView in the Form.

    Imports System.Data.OleDb
    
    Public Class InsertAccess
        Public adapter As OleDbDataAdapter
        Public dt As DataTable
        Private Sub InsertAccess_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            loaddate()
        End Sub
        Private Sub loaddate()
            dt = New DataTable()
            Dim conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database\InsertDate.accdb; Persist Security Info=False;")
            Dim selectSql = "select * from Table1 "
            conn.Open()
            adapter = New OleDbDataAdapter(selectSql, conn)
            adapter.Fill(dt)
            DataGridView1.DataSource = dt
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Try
                Dim scb = New OleDbCommandBuilder(adapter)
                adapter.Update(dt)
                MessageBox.Show("OK!")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    End Class

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 27, 2017 5:52 AM
    Moderator
  • The preview is looking at the database tables in the project folder, not the Bin\Debug folder so you will not see changes this way, there is no way to view the changes via preview.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, April 27, 2017 10:33 AM
    Moderator