Well if it worked once it should work again. However I noticed on your
ListBox1_SelectedIndexChanged you saved the image but did not clear it?
Also I noticed a you did not close the memory stream in ListBox1_SelectedIndexChanged. Just something you might want to think about
So try this code
I'm not sure of the *EXACT* code here but I think you will figure it out.
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
tb_name.Enabled = False
cb_school.Enabled = False
cb_doctype.Enabled = False
Dim test As String = ListBox1.Text
tb_sno.Text = ListBox1.Text.Remove(ListBox1.Text.IndexOf(" "))
If con.State <> ConnectionState.Open Then
con.Open()
End If
GroupBox3.Visible = True
Dim dr As SqlDataReader
sid = ComboBox1.SelectedItem.ToString
sid = sid.Substring(0, 9)
Dim cmd As New SqlCommand("select * from studentmaster a, hbetscan b where a.studentid='" & sid & "' and a.studentid=b.studentid ", con)
cmd.CommandTimeout = 0
cmd.ExecuteNonQuery()
dr = cmd.ExecuteReader
If dr.Read Then
tb_name.Text = dr("studentname")
cb_school.Text = dr("schoolname")
cb_doctype.Text = dr("doctype")
Dim imgdata() As Byte = dr("image")
Dim img As Image
Dim ms As MemoryStream = New MemoryStream(imgdata, 0, imgdata.Length)
ms.Write(imgdata, 0, imgdata.Length)
img = Image.FromStream(ms, True)
PictureBox1.Image = img
PictureBox1.Image.Save("c:\" & "img1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
con.Close()
ms.Dispose()
End If