Display image in picture box of which value is selected from the combobox?
By James J
Depending on the value of combobox it will display image in picturebox...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Conn As SqlConnection = New SqlConnection("connection string")
Dim dr As SqlDataReader
ComboBox1.Items.Clear()
Try
Conn.Open()
Dim cmd As SqlCommand = New SqlCommand("Select Name From Image", Conn)
dr
= cmd.ExecuteReader
While dr.Read()
ComboBox1.Items.Add(dr.GetValue(0).ToString())
End While
dr.Close()
Conn.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
ComboBox1.SelectedIndex = 0
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim Conn As SqlConnection = New SqlConnection("connection string")
Dim dr As SqlDataReader
Try
Conn.Open()
Dim cmd As SqlCommand = New SqlCommand("Select ImageUrl From Image Where Name='" & ComboBox1.SelectedItem.ToString() & "'", Conn)
dr
= cmd.ExecuteReader
While dr.Read()
PictureBox1.Image = Image.FromFile(dr.GetValue(0).ToString())
End While
Conn.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
Display image in picture box of which value is selected from the combobox? (572 Views)