-1

Yes I know what Option Strict does and I use it quite often. My issue is stemming from my Linq query and I can't seem to figure out how to get it from throwing up. I am wanting to get all DataRows in a given table where a row's id equals an id I give it. Also this query works just fine without Option Strict on a I get the rows I need, but I want to have it on.

The error: Option Strict on disallow's late binding

Here's what I have right now...

  Dim cRows() As DataRow = (From cRow In MasterDataSet.Tables(1).Rows Where cRow(childTableKey) = intParID).ToArray

The error is happening underneath: cRow(childTableKey)

I know what the error mean's as well, but can't seem to figure how to stop it from seeing it as an error. I have tried casting it and such already as well...

4

3 回答 3

0

尝试使用

In MasterDataSet.Tables(1) Where CType(cRow(childTableKey), Integer)

代替

In MasterDataSet.Tables(1).Rows Where cRow(childTableKey)

下面的示例使用 Option Strict 对我有用:

    Dim ds As New DataSet
    Dim dt As New DataTable
    ds.Tables.Add(dt)
    Dim dc As New DataColumn
    dc.DataType = GetType(System.Int32)
    dt.Columns.Add(dc)
    Dim dr As DataRow = dt.NewRow
    dr(0) = 10
    dt.Rows.Add(dr)

    Dim rows As DataRow() = (From r In ds.Tables(0) Where CType(r(0), Integer) = 10).ToArray
于 2015-03-20T20:50:47.163 回答
0

尝试这个:

Dim filteredTable1Data= MasterDataSet.Tables(1).AsEnumerable().
    Where(Function(r) r.Field(of Integer)("childTableKey")=intParID)

有关详细信息,请参阅:
LINQ to DataSet 中的查询
LINQ to DataSet 示例
从查询创建数据表 (LINQ to DataSet)

于 2015-03-20T21:34:09.477 回答
0

如果没有额外的扩展,您需要将行从 复制RowCollectionArray. 然后你可以使用 LINQ。

Dim myRows(-1) as DataRow
MasterDataSet.Tables(1).Rows.CopyTo(myRows, 0)

 Dim cRows() As DataRow = (From cRow In myRows 
    Where CInt(cRow(childTableKey)) = intParID).ToArray()
于 2015-03-20T21:37:36.067 回答