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(GetConnectionString(True), strSql, CommandType.Text)
            objSql.ExecuteReader()
            While objSql.Read
                strTitle = objSql.GetString("Title")
                strSNames = strSNames & " " & strTitle
            End While
            objSql.CloseAll()
            Return strSNames
        End Function
newtoperlpgmAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Dim strWhere As String = Append(strWhere, "ObsSID IN (" & strObsSIDs & ")", " AND ")

Open in new window

strWhere is used in the Append, and that makes no sense.
0
ChloesDadCommented:
Change it to

Dim strWhere As String = "ObsSID IN (" & strObsSIDs & ")"

Open in new window


I suspect the original code was building up a complex where clause as the end AND is not needed either
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacques Bourgeois (James Burger)PresidentCommented:
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(GetConnectionString(True), 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.
0
newtoperlpgmAuthor Commented:
Changing it to Dim strWhere As String = "ObsSID IN (" & strObsSIDs & ")" worked.
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.