Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim frm2Search As New Form2
Dim mySqlCommand As SqlCommand
mySqlCommand = New SqlCommand
mySqlCommand.Connection = Me.SqlConnection1
mySqlCommand.CommandType = CommandType.Text
mySqlCommand.CommandText = "SELECT pictureID, pictureTitle, pictureDescription, pictureData FROM Pictures WHERE pictureTitle LIKE @pictureTitle;"
mySqlCommand.Parameters.Add(New SqlParameter("@pictureTitle", SqlDbType.Text))
mySqlCommand.Parameters("@pictureTitle").Value = "%" + Me.TextBoxTitle.Text + "%"
frm2Search.ListView1.Items.Clear()
Try
mySqlCommand.Connection.Open()
Dim myDataReader As SqlDataReader
myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.Default)
Dim pic As picture
While myDataReader.Read
pic = New picture
pic.pictureID = myDataReader.GetValue(0)
pic.pictureTitle = myDataReader.GetValue(1)
pic.pictureDescription = myDataReader.GetValue(2)
pic.pictureData = New System.IO.MemoryStream(myDataReader.GetValue(3), True)
Dim i As ListViewItem = New ListViewItem
i.Text = pic.pictureTitle
i.Tag = pic
frm2Search.ListView1.Items.Add(i)
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
mySqlCommand.Connection.Close()
'ONLY CHANGE IS BELOW HERE:
frm2Search.Show
End Try
End Sub