Hi @Sheelnath Kekre ,
I have made some changes to the code in this reference: 'Database Coding with VB.Net' .
You can refer to the following code to update your datagridview( Also see: How to: Bind data to the Windows Forms DataGridView control ).
'...'
Private bindingSource1 As New BindingSource()
Private Sub GetData(ByVal selectCommand As String)
Dim connectionString As String = "Provider=...;"
da = New OleDbDataAdapter(selectCommand, connectionString)
Dim commandBuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "Contacts")
bindingSource1.DataSource = ds.Tables("Contacts")
DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GetData("SELECT * FROM Contact")
DataGridView1.DataSource = bindingSource1
'...'
End Sub
Private Sub btnReload_Click(sender As Object, e As EventArgs) Handles btnReload.Click
' Reload the data from the database.'
GetData(da.SelectCommand.CommandText)
DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)
End Sub
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
' Update the database with changes in datagridview.'
da.Update(CType(bindingSource1.DataSource, DataTable))
End Sub
Hope it could be helpful.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.