Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a program with 4 datagridviews and im populating them with the following code:
VB
   Private Sub Admin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    CodeMonkey.adminview(InfoDG, "[Info]")
    CodeMonkey.adminview(RoomDG, "[Rooms]")
    CodeMonkey.adminview(UserDG, "[Logins]")
    CodeMonkey.adminview(SettingsDG, "[Monkey]")
End Sub
this is for the form loader, then we have the sub that's being called.
VB
Public Sub adminview(ByVal dgv As DataGridView, ByVal Table As String)
    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM " & Table & "", con)
    con.Open()
    Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
    Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(da)
    Dim ds As DataSet = New DataSet
    da.Fill(ds, Table)
    con.Close()
    dgv.DataSource = ds.Tables(Table).DefaultView
    dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
End Sub

the datagridviews are populating properly and working fine, my issue comes when i want to update the information, how can i set update.

What I have tried:

Originally i had the codes separated for each DGV so i have declared a name for each dataset and other items, so the update was as just useing the command DA.update(DS,Table). but now i dont know the name that holding it. i also tried with the following Sub
VB
Public Sub updater(ByVal Table As String)
    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM " & Table & "", con)
    con.Open()
    Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
    Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(da)
    Dim ds As DataSet = New DataSet
    da.Update(ds, Table)
    ds.AcceptChanges()
    con.Close()
End Sub
this didnt work however
Posted
Updated 22-Sep-17 7:07am

1 solution

I read somewhere that you can use:
dataGridView1.Datasource = Nothing
after that set the Datasource again:
dgv.DataSource = ds.Tables(Table).DefaultView
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900