Imports System.Data.SqlClient
Public Class Form3
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim dr As SqlDataReader
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        con = New SqlConnection("uid=sa;pwd=igiat;database=harsha1")
        cmd = New SqlCommand("select * from student")
        con.open()
        dr = cmd.ExecuteReader()
        While (dr.Read())
            If dr(0).ToString() = TextBox1.Text Then
                Label6.Text = dr(0).ToString()
                Label7.Text = dr(1).ToString()
                Label8.Text = dr(3).ToString()
                Label9.Text = dr(4).ToString()
                Label10.Text = dr(2).ToString()

            End If
        End While
        con.close()
    End Sub

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.Visible = False
       
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form6.Show()
    End Sub
  
End Class

I am not able to initialize connection properly. The error was "ExecuteReader: Connection property has not been initialized". please help me.

Your connection string is wrong. It should be something like:

"Data Source={0};Initial Catalog={1};Integrated Security=False;User Id={2};Password={3};

Also you need to pass your connection to the command:

cmd = New SqlCommand("select * from student", con)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.