[2005] Storing images into data base...plz help me
i m working on an application whisch purpose is to store images into data base.
i m using sql script for this purpose and sql script is given below.
CREATE TABLE [dbo].[Albums] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[desc] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Photos] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[desc] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[album_id] [int] NOT NULL ,
[photo] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE PROCEDURE sp_GetPhotoAlbums AS
SELECT Albums.[id] AS AlbumID, Albums.[name] AS Album, Albums.[desc] AS Album_Desc,
Photos.[id] AS PhotoID, Photos.[name] AS Photo, Photos.photo, Photos.[desc] AS Photo_Desc
FROM Albums INNER JOIN
Photos ON Albums.[id] = Photos.album_id
ORDER BY Albums.[id]
GO
CREATE PROCEDURE sp_InsertPhoto
@name AS VARCHAR(50),
@image AS IMAGE,
@album AS INT
AS
INSERT INTO Photos ([name], photo, album_id)
VALUES (@name, @image, @album)
RETURN @@identity
GO
CREATE PROCEDURE sp_NewAlbum
@name AS VARCHAR(20)
AS
INSERT INTO Albums ([name])
VALUES (@name)
RETURN @@identity
GO
Select * from Photos
when I run my application, it gives an error at the start
The error is "couldn't find stored procedure'sp_GetPhotoAlbums'.
Then I ok this msg and add photos in to the data base.
when I close my application and run it again then there is no photos in to the database
how can I solve this problem.
secondly my apllication shows photo in to the picture box very small and quality of image is not so goood.
i want to show the image big like the size of pic box and quality should be improved
for this purpose i m using this function
Private Sub DrawToScale(ByVal bmp As Image)
' The client rectangle
Dim rc As Rectangle = PictureBox.ClientRectangle
Dim size As New SizeF(bmp.Width / bmp.HorizontalResolution, bmp.Height / bmp.VerticalResolution)
Dim fScale As Single = Math.Min(rc.Width / size.Width, rc.Height / size.Height)
size.Width *= fScale
size.Height *= fScale
' Create a new bitmap of the proper size for the existing bitmap
' and assign it to the picture box
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox1.Image = New Bitmap(bmp, size.ToSize())
End Sub
i m calling this function in to the following function
Private Sub ShowThumbnail(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)
' Get bytes return from stored proc
Dim b As Byte() = CType(cmd.ExecuteScalar(), Byte())
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
i m calling above function in to the tree view event AfterSelect
Private Sub treeAlbum_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeAlbum.AfterSelect
Try
Dim item As TreeItem = DirectCast(e.Node.Tag, TreeItem)
' If the selected item is an album...
If ItemType.Album = item.Type Then
' Set the description
picturebox.Image = Nothing
' Clear the image
Return
End If
' ...otherwise it is a photo
ShowThumbnail(item)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub