代码必须用SQL Server的数据填充Array。 然后将Array数据写入文件。 现在它可以工作,但是可以优化我的“ For Next”。因为Counter可能确实很大,但这不是唯一要填充的数组
For i = 0 To Counter
Dim PR = (SQL.RunReader("SELECT Requirement FROM Programme_Requirements
JOIN Specialities ON Specialities.Id_Speciality=Programme_Requirements.Id_Speciality AND Specialities.SpecialityName='" & SpecialityName(i) &
"' JOIN Educational_Levels ON Educational_Levels.Id_EducationalLevel=Programme_Requirements.Id_EducationalLevel AND
Educational_Levels.EducationalLevel ='" & DocumentTypeId(i) &
"' JOIN Forms_of_Study ON Forms_of_Study.Id_FormofStudy=Programme_Requirements.Id_FormofStudy AND
Forms_of_Study.FormofStudyName ='" & EducationFormName(i) & "'", "Requirement"))
Next
答案 0 :(得分:0)
不确定RunReader中发生了什么,请尝试此操作...
Private Sub ProcessArrays()
Dim strSQL =
"SELECT Requirement FROM Programme_Requirements
JOIN Specialities ON Specialities.Id_Speciality=Programme_Requirements.Id_Speciality
JOIN Educational_Levels ON Educational_Levels.Id_EducationalLevel=Programme_Requirements.Id_EducationalLevel
JOIN Forms_of_Study ON Forms_of_Study.Id_FormofStudy=Programme_Requirements.Id_FormofStudy
WHERE Specialities.SpecialityName= @SpecialtyName
AND
Educational_Levels.EducationalLevel = @DocumentType
AND
Forms_of_Study.FormofStudyName = @EducationFormName;"
Using cn As New SqlConnection("Your connection string")
Using cmd As New SqlCommand(strSQL, cn)
cn.Open()
For i As Integer = 0 To Counter
cmd.Parameters.Add("@SpecialtyName", SqlDbType.VarChar).Value = SpecialtyName(i)
cmd.Parameters.Add("@DocumentName", SqlDbType.VarChar).Value = DocumentTypeId(i)
cmd.Parameters.Add("@EducationFormName", SqlDbType.VarChar).Value = EducationFormName(i)
Using dr As SqlDataReader = cmd.ExecuteReader
'Use reader values
End Using
Next
End Using
End Using
End Sub