gpt4 book ai didi

VB.NET 从数据集中选择列

转载 作者:行者123 更新时间:2023-12-04 05:34:45 25 4
gpt4 key购买 nike

我有以下内容:

    Dim dt As DataTable = ds.Tables(0)

Tables(0) 有大约 20 列。我喜欢只选择一对。 “PrID”是字段之一。

我试过了
    Dim dt As DataTable = ds.Tables(0).Select("PrID")

没有任何成功。任何想法?

最佳答案

一种方法是使用 DataRow扩展方法 Field 它是强类型并支持可为空的类型:

For Each row As DataRow in ds.Tables(0).Rows
Dim PrID As Int32 = row.Field(Of Int32)("PrID")
Next

编辑 : 如果你想要另一个 DataTable对于原始 DataTable 的列子集,您可以使用 DataView表的 ToTable 方法:
Dim displayView = New DataView(ds.Tables(0))
' if you're only interested in: PrID, Col2, Col3
Dim subset As DataTable = displayView.ToTable(false, "PrID", "Col2", "Col3")

关于VB.NET 从数据集中选择列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12100360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com