abhay1234 0 Light Poster

Hello I tried a lot however I have not been able to update data entered in the datagridview into the database table

Any suggestions

Imports System.Data.OleDb

Public Class Form1
    Dim conn As OleDbConnection
    Dim icount As Integer

    Dim datagrid1 As New DataGrid
    Dim da As OleDbDataAdapter
    Dim ds As New DataSet
    Dim cb As OleDbCommandBuilder




    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.Controls.Add(datagrid1)

    End Sub


   
   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=c:\test11.mdb")
        conn.Open()
        Dim da As New OleDbDataAdapter("select * from table1", conn)
        Dim ds As New DataSet
        da.Fill(ds, "Table1")
        DataGridView1.DataSource = ds.Tables("Table1")
        conn.Close()

    End Sub

    Private Sub buttonclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        conn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=c:\test11.mdb")
        conn.Open()
        Dim da As New OleDbDataAdapter("select * from Table1", conn)
        Dim ds As New DataSet
        da.Fill(ds, "Table1")
        'DataGridView1.DataSource = ds.Tables("Table1")
        da.TableMappings.Add("Table", "Table1")
        cb = New OleDbCommandBuilder(da)
        da.Update(ds)

        conn.Close()

    End Sub

End Class
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.