Private Sub searchTitle()
'declare a new sqlcommand
Dim command As SqlCommand = New SqlCommand
'set the command type to text
command.CommandType = CommandType.Text
'specify the connection to use
command.Connection = SqlConnection1
'declare the SQL statement to use in the command text
command.CommandText = "SELECT pictureID, pictureTitle, pictureDescription, pictureOwner, pictureData FROM dbo.Pictures WHERE (pictureTitle LIKE @pictureTitle)"
command.Parameters.Add(New SqlParameter("@pictureTitle", SqlDbType.VarChar))
command.Parameters("@pictureTitle").Value = "%" + TextBoxTitle.Text + "%"
Try
'clear listviewleft
ListViewLeft.Items.Clear()
'open connection
command.Connection.Open()
'declare sqldataread
Dim dr As SqlDataReader
dr = command.ExecuteReader(CommandBehavior.Default)
'declare a variable of class picture
Dim picture As picture
While dr.Read
'create a new picture
picture = New picture
'assaign the relevant information to each part of picture
picture.pictureTitle = dr.GetValue(1)
'read a memorystream of bytes fromt he database and put it into the pictureData variable
picture.pictureData = New System.IO.MemoryStream(dr("pictureData"), True)
picture.pictureDescription = dr.GetValue(2)
picture.pictureID = dr.GetValue(0)
'declare a new listviewitem
Dim i As ListViewItem = New ListViewItem
'set the TAG of the new listviewitem to be equal to picture
i.Tag = picture
'set the TEXT of the new listviewitem to be equal to picture.pictureTitle
i.Text = picture.pictureTitle
'add the new listviewitem to listviewleft
ListViewLeft.Items.Add(i)
End While
Catch ex As Exception
StatusBar.Text = "Status: " & ex.Message
Finally
'close connection
command.Connection.Close()
'update status bar with how many files were found
StatusBar.Text = "Status: " & ListViewLeft.Items.Count & " files found"
End Try
End Sub