在数据集中查找具有主键值的行

To find a row in dataset with a primary key value

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

我是否必须初始化数据table?如何 ?我还以为你初始化数据库的时候数据table已经填满了

ds as new dsPart

我的table适配器内部数据集查询如下。数据集名称是 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。 存在。 车辆table的内容为: +----------------+--------+------------+
|属性值 |价值 | Expr2 |
+----------------+--------+------------+
| 2132 |本田 | new_vehicle |
| 3214 |丰田 | new_vehicle |
| 3546 |斯巴鲁 | new_vehicle |
+----------------+--------+------------+

感谢您的帮助。

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

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#代码,所以请原谅小的语法错误。