如何获取连接表的正确索引 [英] how to get the correct index of a joined table
问题描述
daJoin = New OleDbDataAdapter("SELECT Company.CompanyID, Company.CompanyName, Product.ProductID, Product.ProductDesc, Product.RawMatDesc FROM (Product " &
"INNER JOIN Company ON Company.CompanyID=Product.CompanyID)", con)
daJoin.Fill(dsJoin, "Product")
con.Close()
dgvProdView.DataSource = dsJoin.Tables("Product")
你在上面看到的是我的代码,它将数据产品和公司合并为1个数据网格。
接下来我要做的就是准确使用datagridview事件显示数据cellmouseclick。
What you are seeing above this is my code that will combine datatable Product and Company into 1 datagridview.
The next thing I want to do is to get the exact displayed data using the datagridview event cellmouseclick.
Private Sub btnSelProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelProd.Click
indexProd = dgvProdView.CurrentRow.Index
txtProdDesc.Text = ds.Tables("Product").Rows(indexProd).Item("ProductDesc")
txtRawMatDesc.Text = ds.Tables("Product").Rows(indexProd).Item("RawMatDesc")
End Sub
那里的代码对我来说非常好。它将确切的显示传输到我的数据表中,但是当我添加另一个语句时。
The codes there worked perfectly fine for me. it transfers the exact display into my datatable but when I added another statement.
Private Sub btnSelProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelProd.Click
indexProd = dgvProdView.CurrentRow.Index
'I added txtComp to get the Company name of the joined table
txtCompName.Text = ds.Tables("Company").Rows(indexProd).Item("CompanyName")
txtProdDesc.Text = ds.Tables("Product").Rows(indexProd).Item("ProductDesc")
txtRawMatDesc.Text = ds.Tables("Product").Rows(indexProd).Item("RawMatDesc")
End Sub
当我试图运行它并点击datagridview,它没有给我显示的公司名称,而是给了我一个公司名称甚至没有在联合表格显示中。
需要帮助伙伴。
When I tried to run it and clicked the datagridview, it did'not gave me the displayed companyname but rather it gave me a Companyname that was not even in the joined table display.
Need help mates.
推荐答案
我现在知道什么问题傻了我>。<< br mode =hold/>
dsJoin 这段代码是我所缺乏的。我忘记了我在表单中调用了2个数据集。谢谢:)
I now know what is the problem silly me >.<<br mode="hold" />
"dsJoin" this code is what I am lacking. I forget that I have 2 Datasets being called inside the form. Thanks though :)
这篇关于如何获取连接表的正确索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!