如何在创建它们时更新我的ds。 [英] How can I update my ds when this is how I have created them.
问题描述
我有一个包含4个datagridviews的程序,并使用以下代码填充它们:
i have a program with 4 datagridviews and im populating them with the following code:
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.
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
datagridviews正确填充并且工作正常,我的问题出现在我想要更新信息时,我该如何设置更新。
我的尝试:
最初我为每个DGV分配了代码,因此我已经为每个数据集和其他项目声明了名称,因此更新只是使用命令DA.update(DS,Table)。但现在我不知道拿着它的名字。我也尝试使用以下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
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
这不起作用但
推荐答案
我读到了你可以使用的地方:
I read somewhere that you can use:
dataGridView1.Datasource = Nothing
之后再次设置数据源:
after that set the Datasource again:
dgv.DataSource = ds.Tables(Table).DefaultView
这篇关于如何在创建它们时更新我的ds。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!