vb.net 如何从数据表中选择数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9412466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:57:11 来源:igfitidea点击:
How to select data from datatable
提问by lawphotog
I am little bit stuck here .. I have a datatable as _
我有点卡在这里..我有一个数据表 _
Dim dtPupil As New DataTable
dtPupil.Columns.Add("PupilId", GetType(Integer))
dtPupil.Columns.Add("Forename", GetType(String))
dtPupil.Columns.Add("Surname", GetType(String))
I made a select (assuming names combination will be unique)
我做了一个选择(假设名称组合将是唯一的)
Dim strQuery As String = "Forename ='" & forename & "' and Surname = '" & surname & "'"
Dim dr As DataRow()
dr = dTablePupil.Select(strQuery)
I wanna have PupilId
as an Integer of the row that match, so
我想要PupilId
作为匹配行的整数,所以
Dim PupilID As Integer = ??????????
What do I need to write here? There will only be 1 row returned.
我需要在这里写什么?只会返回 1 行。
回答by adatapost
Firstly check the length of DataRow
array,
首先检查DataRow
数组的长度,
IF dr.Length<>0 Then
PupilID= CType(dr(0)("PupilId"),Integer)
End If