无法在图片框中获取图片 [英] unable in getting the picture in the picture box

查看:75
本文介绍了无法在图片框中获取图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个程序,其中文档列表在列表框中可见,图像在图片框中显示.但是当我运行代码时,当我在列表框中选择一个文档时,我在图片框中得到了它的图像,但是当我选择另一个文档时,我却在图片框中得到了它的相应图像.当我单击第一个文档时,图像在图片框中保持静态……
请帮助我...这是我的代码

- - - - - - - - - - - - - - - -代码 - - - - - - - - - -------------------------------

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-------------------------------------------------

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]已添加代码块-OriginalGriff [/edit]




[edit]Code block added - OriginalGriff[/edit]

推荐答案

您需要检查该方法是否正在执行-将断点放在顶部(在tb_name.Enabled = False行),然后在每次您认为它被调用时调用该例程.
如果是这样,那么当您达到断点时,请单步执行代码.可能是在构造选择命令时sid中的值有问题-但您应该能够通过逐步执行来查看.
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.


这篇关于无法在图片框中获取图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆