S
Sean
Maybe I'm just not understanding these SQLReaders. When I
get to trying to read a column's value:
Result = SQLReader.Item("ColumnName")
, I get an exception of trying to read value when no value
is present.
Here is the code....
Public Function GetEncounterFormID(ByVal strName As
String) As Integer
Dim SQLReader As SqlClient.SqlDataReader ' SQL
Reader
Dim strSQL As String ' Transacat-SQL Statement
Dim intResult As Integer ' Function result value
intResult = -1 ' Initialize result value
' Transact-SQL Select Statement
strSQL = "SELECT EncounterFormID FROM
EncounterForm WHERE " _
& "Name = '" & strName & "'"
' Assign SQL Statement
m_SQLCommand.CommandText = strSQL
Try ' Catch any SQL Exceptions
' Create the Reader (holds result dataset)
SQLReader = m_SQLCommand.ExecuteReader()
' If a record was found
If SQLReader.HasRows = True Then
' ************* Blows up on this line *******************
intResult = SQLReader.Item ("EncounterFormID")
End If
SQLReader.Close() ' Close the SQL Reader
' Handle SQL Exception
Catch er As SqlClient.SqlException
intResult = -1
End Try
Return intResult ' Return ID or -1 on Failure
End Function
get to trying to read a column's value:
Result = SQLReader.Item("ColumnName")
, I get an exception of trying to read value when no value
is present.
Here is the code....
Public Function GetEncounterFormID(ByVal strName As
String) As Integer
Dim SQLReader As SqlClient.SqlDataReader ' SQL
Reader
Dim strSQL As String ' Transacat-SQL Statement
Dim intResult As Integer ' Function result value
intResult = -1 ' Initialize result value
' Transact-SQL Select Statement
strSQL = "SELECT EncounterFormID FROM
EncounterForm WHERE " _
& "Name = '" & strName & "'"
' Assign SQL Statement
m_SQLCommand.CommandText = strSQL
Try ' Catch any SQL Exceptions
' Create the Reader (holds result dataset)
SQLReader = m_SQLCommand.ExecuteReader()
' If a record was found
If SQLReader.HasRows = True Then
' ************* Blows up on this line *******************
intResult = SQLReader.Item ("EncounterFormID")
End If
SQLReader.Close() ' Close the SQL Reader
' Handle SQL Exception
Catch er As SqlClient.SqlException
intResult = -1
End Try
Return intResult ' Return ID or -1 on Failure
End Function