Question

I need to load a DataTable from Microsoft Access into a DataSet using OleDb. I need to load that DataSet into a DataGridView. I then need to make changes to the DataGridView and update those changes in the original DataTable in Microsoft Access.

Here is my code so far:

Public tblName As String = "Criteria"

Dim ds As New DataSet()
Dim da As OleDbDataAdapter
Dim cmdBuilder As OleDbCommandBuilder
Dim Bsource As New BindingSource

Public Sub Show_Panel_Manage_Calculations()
    Panel_Manage_Calculations.Show()

    Nordeen_Investing_3.con.Open()
    da = New OleDbDataAdapter("SELECT Calculation, [Interval], Formula FROM " & tblName & "", Nordeen_Investing_3.con)
    cmdBuilder = New OleDbCommandBuilder(da)
    da.Fill(ds, "Criteria")

    Bsource.DataSource = ds
    DataGridView_Manage_Calculations.DataSource = Bsource
    Nordeen_Investing_3.con.Close()

End Sub

Private Sub Button_Update_Click(sender As Object, e As EventArgs) Handles Button_Update.Click
    Nordeen_Investing_3.con.Open()
    da.Update(ds, "Criteria")
    Nordeen_Investing_3.con.Close()
End Sub

Right now my data from the DataTable is not being displayed in my DataGridView.

Was it helpful?

Solution

The DataSource expects a Table, not the whole DataSet. Also you don't need the BindingSource part. Sample code:

DataGridView_Manage_Calculations.DataSource = ds.Tables(0) 'By assuming that you want the first table
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top