【问题标题】:To find a row in dataset with a primary key value在数据集中查找具有主键值的行
【发布时间】:2015-02-27 18:38:30
【问题描述】:

帮助,return dr 什么也没给我。我知道我错过了一些东西。我是这个数据集数据表的新手。请给我一些方向。谢谢

我必须初始化数据表吗?如何 ?我以为你初始化数据库时数据表已经填满了

ds as new dsPart

我在数据集查询中的表适配器如下。数据集名称为 dsPart

SELECT     AttributeValue, Value, Expr2
FROM   Vehicle

AttributeValue 设置为主键

Public Function getVehicleRow(ByVal iRideVehicle As Integer) As dsPart.VehicleRow
   Dim ds As New dsPart
   If iRideVehicle = 0 Then Return Nothing
   Dim dr As dsPart.VehicleRow = ds.Vehicle.FindByAttributeValue(iRideVehicle)
   Return dr
End Function

调用此函数时 irideVehicle 的值为 2132。 存在的。 车辆表的内容为: +-----------------+--------+-------------+
|属性值 |价值 | Expr2 |
+-----------------+--------+-------------+
|第2132章本田 |新车 |
| 3214 |丰田 |新车 |
| 3546 |斯巴鲁 |新车 |
+-----------------+--------+-------------+

感谢您的帮助。

【问题讨论】:

  • 您没有将任何数据填充到您的数据集中 - 因此当您调用 FindByAttributeValue(..) 时您将找不到任何东西

标签: vb.net dataset


【解决方案1】:

正如我在评论中提到的,我认为忘记将数据从您的数据存储中加载到您的数据集中。

Public Function getVehicleRow(ByVal iRideVehicle As Integer) As dsPart.VehicleRow
    Dim ds As New dsPart
    Dim da as new VehicleTableAdapter() ' Created TableAdapter
    da.Fill(ds.Vehicle)  ' Load data into dataTable
    If iRideVehicle = 0 Then Return Nothing
    Dim dr As dsPart.VehicleRow = ds.Vehicle.FindByAttributeValue(iRideVehicle)
    Return dr
End Function

我习惯写c#代码,所以请原谅一些小的语法错误。

【讨论】:

    猜你喜欢
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 2013-07-24
    • 2016-08-28
    相关资源
    最近更新 更多