aamir55 0 Newbie Poster

i m working on a small application
its main function is to create a album and then add photos in the album.
i m using tree view for creating album and photos
i m using tree root as album and nodes as photos.
i have to also show photos when i click on photo name
i m using function showphoto for this purpose
i m using sql server to store picture in database and then retrieve from it
but i also want to generate thumbnail when i click on album name and all the images should be displayed as thumbnail on picbox
is there any control for this purpose or how i can do that?
i m also sending this application plz help me
Private Sub ShowPhoto(ByVal item As TreeItem)

Try

Create a command to select the selected photo

Dim strCmd As String = [String].Format("SELECT photo FROM Photos WHERE id = {0}", item.Id)
Dim cmd As New SqlCommand(strCmd, sqlConn)

Set the description

lblDesc.Text = item.Desc

Get bytes return from stored proc

Dim b As Byte() = CByte(cmd.ExecuteScalar())
If b.Length > 0 Then
' Open a stream for the image and write the bytes into it
Dim stream As New System.IO.MemoryStream(b, True)
stream.Write(b, 0, b.Length)

Draw photo to scale of picturebox

DrawToScale(New Bitmap(stream))

Close the stream and delete the temp file

stream.Close()
End If
Catch e As Exception
MessageBox.Show(e.Message)
End Try
End Sub

if i use above function to show photo
error comes on this line

Dim b As Byte() = CByte(cmd.ExecuteScalar())

and erroe says "Error 1 Value of type 'Byte' cannot be converted to '1-dimensional array of Byte'"
if i remove Cbyte from above line then application runs well but when i click on photo name then picture doesn't appear in picturebox.
and i m using showphoto function in below code snipts

Private Sub treeAlbum_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeAlbum.AfterSelect

Try

Disable edit controls if we were in edit mode

If True = btnUpdate.Visible Then
btnUpdate.Visible = False
txtDesc.Visible = False
lblDesc.Visible = True
End If

Retrieve the item info for this node

Dim item As TreeItem = DirectCast(e.Node.Tag, TreeItem)

If the selected item is an album...

If ItemType.Album = item.Type Then
lblDesc.Text = item.Desc
' Set the description
PictureBox.Image = Nothing
' Clear the image
Return
End If

...otherwise it is a photo

ShowPhoto(item)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.