如何将数据集表分配给新数据表? [英] How do I assign dataset table to a new datatable?
问题描述
我正在尝试从DGV更新数据库表(projenv)。
这些变量也用于DGV。此代码适用于另一个DB和DGV。我只更改了变量名称。
i得到错误
i am trying to update a database table ("projenv") from a DGV.
the variables are also used for the DGV. this code works for another DB and DGV. i only changed the variable names.
i get an error
ds2.tables显示DGV表就好了。 dt2不接受数据集。
ds2.tables shows the DGV tables just fine. dt2 will not accept the dataset.
Public Class Form4
Dim dt2 As DataTable
Dim da2 As MySqlDataAdapter
Dim ds2 As DataSet
Dim bsource2 As BindingSource = New BindingSource()
Private Sub BtnHtUpdate_Click(sender As Object, e As EventArgs) Handles BtnHtUpdate.Click
Dim dt2 As New DataTable
dt2 = ds2.Tables("projenv") {problem is here}
DGVEnvHtg.BindingContext(dt2).EndCurrentEdit()
da2.Update(dt2)
End Sub
任何帮助将不胜感激。
谢谢,
我尝试过:
i搜索了谷歌,bing,duckduckgo。我已经将这段代码与一个有效的副本进行了比较(变量已经改变)并且无法弄清楚为什么它不起作用。
这是我第一次发布问题,如果我没有关注,我道歉正确的协议
any help would be greatly appreciated.
thanks,
What I have tried:
i have searched google, bing, duckduckgo. i have compared this code with an exact copy that works (variables changed) and cannot figured why it doesn't work.
this is my first time posting a question, i apologize if i didn't follow the proper protocol
推荐答案
我认为问题在这里(突出显示),
Hi,
I think the problem is here(Highlighted),
Private Sub BtnHtUpdate_Click(sender As Object, e As EventArgs) Handles BtnHtUpdate.Click
Dim dt2 As New DataTable
dt2 = ds2.Tables("projenv") {problem is here}
DGVEnvHtg.BindingContext(dt2).EndCurrentEdit()
da2.Update(dt2)
End Sub
try
try
dt2 As New DataTable
而不是
instead of
Dim dt2 As New DataTable
已经尝试过
Dim dt2 As DataTable
Dim dt2作为新的DataTable
dt2 As New DataTable - 给出错误表达式不是方法
have tried
Dim dt2 As DataTable
Dim dt2 As new DataTable
dt2 As New DataTable - gives an error "expression not a method"
这篇关于如何将数据集表分配给新数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!