newtoperlpgm
asked on
Getting Error Variable is used before it has been assigned a value. A null reference exception could result at runtime.
Here is my code.
Public Shared Function GetObsSNames(ByVal strObsStIDs As String) As String
Dim strWhere As String = Append(strWhere, "ObsSID IN (" & strObsSIDs & ")", " AND ")
Dim strSql As String = "SELECT * FROM ObsS WHERE " & strWhere
Dim strSNames As String = ""
Dim strTitle As String = ""
Dim objSql As New SqlDataAccess(GetConnectio nString(Tr ue), strSql, CommandType.Text)
objSql.ExecuteReader()
While objSql.Read
strTitle = objSql.GetString("Title")
strSNames = strSNames & " " & strTitle
End While
objSql.CloseAll()
Return strSNames
End Function
Public Shared Function GetObsSNames(ByVal strObsStIDs As String) As String
Dim strWhere As String = Append(strWhere, "ObsSID IN (" & strObsSIDs & ")", " AND ")
Dim strSql As String = "SELECT * FROM ObsS WHERE " & strWhere
Dim strSNames As String = ""
Dim strTitle As String = ""
Dim objSql As New SqlDataAccess(GetConnectio
objSql.ExecuteReader()
While objSql.Read
strTitle = objSql.GetString("Title")
strSNames = strSNames & " " & strTitle
End While
objSql.CloseAll()
Return strSNames
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When you say that you have an error, please tell us on which line. We have to spend time on all the code while we could focus directly on the error if we knew where it occurs.
Also, strWhere ends the command (strSql), so the command is incomplete because it terminates abruptly with AND (unless Append adds something else).
Also, what is the type of
Dim objSql As (???) = New SqlDataAccess(GetConnectio nString(Tr ue), strSql, CommandType.Text)
Finally, you way of returning the data might be problematic. If a title contains spaces, it will be mixed up with everything else because the titles are separated by spaces in strNames. You should separate the results with a character that you are sure will not appear in any title. The pipe character "|" or a tabulation (vbTab) is often used in these situations.
Also, strWhere ends the command (strSql), so the command is incomplete because it terminates abruptly with AND (unless Append adds something else).
Also, what is the type of
Dim objSql As (???) = New SqlDataAccess(GetConnectio
Finally, you way of returning the data might be problematic. If a title contains spaces, it will be mixed up with everything else because the titles are separated by spaces in strNames. You should separate the results with a character that you are sure will not appear in any title. The pipe character "|" or a tabulation (vbTab) is often used in these situations.
ASKER
Changing it to Dim strWhere As String = "ObsSID IN (" & strObsSIDs & ")" worked.
Thanks.
Thanks.
Open in new window
strWhere is used in the Append, and that makes no sense.