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.