  'for module
Imports System.Data.SqlClient
Module Module1
    Public Con As SqlConnection
    Public cons As String
    Public usertype As String


    Public Sub main()

        cons = "Data Source=127.0.0.1,49166;Network Library=DBMSSOCN;Initial Catalog=packwelldata;User ID=sa;Password=bedarsi;Trusted_Connection=False;"
        Con = New SqlConnection(cons)
        Try
            Con.Open()
            'MsgBox("Server Connection is Open ! ")
            Con.Close()
        Catch ex As Exception
            MsgBox("Sorry Can not open connection ! ")

        End Try


    End Sub
End Module




'for button

Call main()
        Con.Open()


        Dim cmd As New SqlCommand("SELECT * FROM tbnetid WHERE network_id = '" & txtshow.Text & "'", Con)

        Dim ndr As SqlDataReader = cmd.ExecuteReader()
      
        ' If the record can be queried, it means passing verification, then open another form.  
        Dim startVal = 1
        Dim endVal = 5
        For var = startVal To endVal
            If (ndr.Read() = True) Then
                DataGridView1.Columns(0).DefaultCellStyle.NullValue = ndr(0)
                DataGridView1.Columns(1).DefaultCellStyle.NullValue = ndr(1)
            End If
        Next var
        Con.Close()