我想让我的读者的结果能够WHERE
在另一个 SQL 命令的子句中使用。我试图将阅读器放入一个变量中使用,但它不起作用。我以前从未使用过阅读器,所以我不知道它们是如何工作的。谁能告诉我如何让读者的结果进入where语句?谢谢。
编码:
Dim courseSelectCom = New SqlCommand("select stuff((select ','+course_name from course where school= '" & schoolSelect & "' for xml path ('')), 1, 1, '')", connection)
Dim reader = courseSelectCom.ExecuteReader()
If reader.Read() Then
Dim courseVar As String
courseVar = "%" & reader("course_name") & "%"
Using totalStudentCom = New SqlCommand("SELECT COUNT(student_ID) FROM student " & "course_name like @course", connection)
totalStudentCom.Parameters.AddWithValue("@course", courseVar)
Dim result = totalStudentCom.ExecuteScalar()
MessageBox.Show("Students for course = " & result.ToString)
End Using
End If