We help IT Professionals succeed at work.

Receiving a Function warning after converting VB.net for VS 2003 to VS 2005.

Richard Comito
on
Medium Priority
219 Views
Last Modified: 2010-04-23
I am converting a project that I was working on in VS 2003 but after I converted this project to VS 2005 I get the following error:

"Function 'selAllOrgMembers' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used."

Here is the function.

    Public Function selAllOrgMembers() As SqlDataAdapter
        Try
            Dim cmdAllOrgMembers As New SqlCommand("selAllOrgMembers", objConn)
            cmdAllOrgMembers.CommandType = CommandType.StoredProcedure
            objConn.Open()
            cmdAllOrgMembers.ExecuteNonQuery()
            objConn.Close()
            selAllOrgMembers = New SqlDataAdapter(cmdAllOrgMembers)
        Catch ex As SqlException
            MsgBox(ex.Message)
        End Try
    End Function

When I run this it works fine.  I am just trying to eliminate all the warnings I have and clean up my code.

How would I fix this warning that I am getting?

Thanks
Comment
Watch Question

Senior Systems and Integration Developer
CERTIFIED EXPERT
Commented:
Presumably it is because you do not have a return statement for your Catch block. You may just want to return null either in the catch block or after it as a default.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
Hi GabicusC,

You may add "return nothing" before the "end try"  

Cheers!
Richard ComitoDirector of IT

Author

Commented:
Thanks carl_tawn and emoreau for your replys.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.