I do not understand why the following code is returning 0 instead of 475:
Public Function getSectionLength(sectionUID As Integer) As Integer
Dim sectionLength As Integer = 0
Using dr As New DataReader(globals.dif)
Dim SQL As String = "SELECT dbo.SA.SECTION_LENGTH
FROM dbo.SA WHERE dbo.SA.SECTION_UID =
@sectionUid"
Dim paramList As New List(Of SqlClient.SqlParameter)
paramList.Add(New SqlClient.SqlParameter("@sectionUid",
sectionUID))
dr.ExecuteReader(SQL, paramList)
If dr.Read Then
sectionLength = dr("SECTION_LENGTH")
End If
End Using
Return sectionLength
End Function
Here are the values of the variables:
sectionUID = 38
When I run the SQL query in SSMS and swap @sectionUid for 38 I get:
SECTION_LENGTH = 475
but
dr.Read = False
How can dr.Read be false?
EDIT: This has been solved. The issue had to do with the globals.dif. It was being initialised first, but then the values were changed before the program hit this function, causing the error. I solved it by re-initialising the dif within the getSectionLength function.