troubleshooting Question

System.NullReferenceException: Object reference not set to an instance of an object.

Avatar of Member_2_5230414
Member_2_5230414 asked on
Visual Basic.NET
8 Comments1 Solution712 ViewsLast Modified:
i keep getitng the error "System.NullReferenceException: Object reference not set to an instance of an object."

Shared Function pstcount(ByVal forumname As String) As Results
        Dim con As New SqlConnection(local)
        Dim cmd As New SqlCommand
        cmd.Connection = con
        cmd.Parameters.AddWithValue("@forumname", forumname)
        Try
            con.Open()
            cmd.CommandText = "Select Count(*) From forum where Forum =@forumname"
            Dim Res As Results
            Res.Result1 = cmd.ExecuteScalar()
            cmd.CommandText = "Select Count(*) From forum where Forum =@forumname and numrep = 0  "
            Res.Result2 = cmd.ExecuteScalar()
            cmd.CommandText = "Select TOP 1  title +'|'+ LastPoster +'|'+ CONVERT(VARCHAR(256), lasttime, 120) +'|'+ CAST(ID AS VARCHAR(256)) +'|'+ CAST(numrep AS VARCHAR(256)) from forum where Forum =@forumname order by lasttime DESC"
            Res.Result3 = cmd.ExecuteScalar()

            Return (Res)
        Catch ex As Exception
            Throw ex
        Finally
            con.Close()
        End Try
    End Function


using :    lastrep.Text = res.Result3.Split("|")(3)

i dont understand where the error is coming from
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros