首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用"DataTable.Select(?)“在主从关系中

如何使用"DataTable.Select(?)“在主从关系中
EN

Stack Overflow用户
提问于 2011-06-23 16:23:45
回答 1查看 1.6K关注 0票数 0
代码语言:javascript
复制
DataTable with Master Detail relationship in Dataset:

**product** 
--------------
product_id      (pK)
product_name       
product_price

**operator**
--------------
operator_id     (pK)   
operator_name

**machine**
--------------
machine_id      (pK)
product_id      (fK)
operator_id     (fK)


Contents of the DataTable is

**product** 
--------------
1   bag       20
2   shoe      15
3   clothes   30

**operator**
--------------
1   alex
2   bery

**machine**
--------------
1   1    1
2   2    2

我想使用DataTable.Select(?)显示下面的数据。多么?谢谢。

代码语言:javascript
复制
**machine**
--------------
1    bag    alex
2    shoe   bery

这个程序正在运行,只有结果输出是(1 1 1),我希望输出像这样(1袋alex)

代码语言:javascript
复制
Dim dtTable As DataTable = MyDataset.Tables("machine")
Dim rowSearching() As DataRow

Try

   ' Problem in here... "dtTable.Select"
   rowSearching = dtTable.Select("Parent(fk_machine_product_id).product_id = product_id AND Parent(fk_machine_totalizer_id).totalizer_id = totalizer_id AND Parent(fk_machine_operator_id).operator_id = operator_id")

   If rowSearching.Length > 0 Then
      For Each dr As DataRow In rowSearching
        MessageBox.Show(CStr(dr.Item(0)) & " " & CStr(dr.Item(1)) & " " & CStr(dr.Item(2)))
      Next
   End If

Catch ex As Exception
   MessageBox.Show(ex.Message)
End Try


Thanks & Best Regard,
Dewi
EN

回答 1

Stack Overflow用户

发布于 2011-06-24 02:17:36

@magnus,我根据你的参考找到了一个解决方案,谢谢。

我不使用"DataTable.Select (?)“而是"GetParentRow“细节如下,我将分享可能对其他人有用。谢谢。

代码语言:javascript
复制
Dim childMachineDataTable As DataTable = MyDataset.Tables("machine")

Dim parentProductRow As DataRow = Nothing
Dim parentOperatorRow As DataRow = Nothing

Dim productName As New ArrayList
productName.Clear()

Dim operatorName As New ArrayList
operatorName.Clear()

For Each childRow As DataRow In childMachineDataTable.Rows
    parentProductRow = childRow.GetParentRow("fk_machine_product_id")
    parentOperatorRow = childRow.GetParentRow("fk_machine_operator_id")

    productName.Add(parentProductRow.Item(1))
    operatorName.Add(parentOperatorRow.Item(1))
Next

MessageBox.Show(CStr(productName.Item(0))  ' output: bag
MessageBox.Show(CStr(productName.Item(1))  ' output: shoe

MessageBox.Show(CStr(operatorName.Item(0)) ' output: alex
MessageBox.Show(CStr(operatorName.Item(1)) ' output: bary
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6451220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档