troubleshooting Question

How to rectify error in Vb.Net Windows form for click on button for db connectivity issues

Avatar of searchsanjaysharma
searchsanjaysharma asked on
Visual Basic.NET
3 Comments1 Solution357 ViewsLast Modified:
There is a textbox txtauin and button btnuin.
The users enters the uin and click on uin and get the details.
But if txtauin is blank and user clicks on btnuin, then the error comes Object reference not set to instance of an object.

Code is here.

    Private Sub btnuin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnuin.Click
            If (txtauin.Text.Trim() <> "") Then
                con = New SqlConnection("Data Source=;Initial Catalog=testadms;User Id=sa;Password=admin#cgc;")
                s = "SELECT isnull(ahstatus,'') from mststudents where uin='" & txtauin.Text.Trim() & "'"

                If (con.State = ConnectionState.Closed) Then
                End If
                da = New SqlDataAdapter(s, con)
                dt = New DataTable


                If (dt.Rows.Count = 0) Then
                    MessageBox.Show("No Record Found")
                    txtauin.Text = ""
                    txtahstatus.Text = dt.Rows(0)(0).ToString()
                                End If
            end if

                MsgBox("Invalid UIN")
            End If
        Catch ex As Exception
        End Try
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
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 3 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