具有多列的DataSet和主键

时间:2009-11-12 12:51:21

标签: dataset primary-key multiple-columns

如何在具有3列主键的DataSet中使用Find方法?

        dadSample.SelectCommand = New SqlCommand("SELECT * FROM StockBalance", conxMain)
        dadSample.FillSchema(dsSample, SchemaType.Source, "StockBalance")
        dadSample.Fill(dsSample, "Stock")

        Dim keyColStock(3) As DataColumn
        keyColStock(0) = dsSample.Tables("StockBalance").Columns("StockID")
        keyColStock(1) = dsSample.Tables("StockBalance").Columns("LocationID")
        keyColStock(2) = dsSample.Tables("StockBalance").Columns("StockBalanceUnitID")
        dsSample.Tables("StockBalance").PrimaryKey = keyColStkBal

        dRowCurrent = dsSample.Tables("StockBalance").Rows.Find("")

在Find参数中,我必须填写哪一个? 请帮我。谢谢大家!

2 个答案:

答案 0 :(得分:2)

这是关于你的问题的帖子 - 他们建议你传递一个列数组(用于键)并将其转换为对象[]

Find with more than one columns in key

答案 1 :(得分:1)

搜索数组,而不是单个值。

类似的东西:

Dim ObjectFindArray(2) as Object 
...
ObjectFindArray[0] = 
...
dRowCurrent = dsSample.Tables("StockBalance").Rows.Find(ObjectFindArray)
...