Click here to Skip to main content
15,921,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am running a program in which the list of documents is visible in the listbox and the image is shown in the picture box. but when i run the code and when i select a document in the listbox ,i got its image in the picturebox but when i select another document i dint get its respective image in picturebox. the image remains static in the picturebox when i clicked the first document......
plz help me plzzz...........here's my code

-------------------------------code-------------------------------------------------
VB
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
     'tb_sno.Enabled = False

     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
     Dim sid As String
     sid = ComboBox1.SelectedItem.ToString
     sid = sid.Substring(0, 9)
     ' school = ComboBox2.Text
     'dname = ListBox1.Items.Add(dr(0))
     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_sid.Text = dr("studentid")
         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)
         dr.Close()
         con.Close()
         ms.Close()
         'ms.Dispose()

 
     End If
 End Sub



[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 17-Apr-12 0:00am
v2

1 solution

You need to check if the method is being executed - put a breakpoint at the top (on the tb_name.Enabled = False line) and cehck that the routine is called each time you think it is.
If it is, then when you hit the breakpoint, single step through your code. The chances are that it is a problem with the value in sid when you construct the select command - but you should be able to see that by stepping through.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900