从我的TableAdapter SELECT语句中,我做了一个
SELECT StudentID FROM dbo.Student WHERE Email = @Email
在我的.vb代码中,我调用该函数并为每个循环执行以下操作:
Dim myStudentID As Integer
Dim myTable = StudentTableAdapter1.GetStudentID("myEmail@mail.com")
For Each myRow As DataRow In myTable.Rows
myStudentID = myRow.Item("StudentID")
MessageBox.Show(myStudentID)
Next
但我希望进一步缩短这一点。有没有办法让行更快?
答案 0 :(得分:0)
如果您完全确定只返回一行,则可以执行以下操作:
Dim myStudentID As Integer
Dim myTable = StudentTableAdapter1.GetStudentID("myEmail@mail.com")
myStudentID = myTable(0)("StudentID")
MessageBox.Show(myStudentID)