Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I am storing images in my database, where I am using 3 columns for each image, 1. imageName as an nvarchar(50), 2. imageData as an image, and 3. imageType as an nvarchar(100).

 

I have successfully inserted the images into the database, only problem that I am having is that I am unable to do any sort of compression on the images, but that's a different problem. The issue that I am having is that if I try and retrieve two images from the database and display them at the same time, in some cases only 1 image is displayed while in other cases no image is displayed.

 

To display the images, I have created a web control with two html image controls with runat="server", both these controls have the image url set to a different .aspx page which use the following code to retrieve the image from the database and display it:

Private Sub LoadImage()
       Dim myReader As Byte()
       Dim content As String = String.Empty

       myReader = dbConnection.RetrievePhoto(Request.QueryString("pid").ToString, 0, content)

       Try
           Response.ContentType = content
           If Not myReader Is Nothing Then
               Response.BinaryWrite(myReader)
           Else
               Response.WriteFile("images/Notfound.jpg")
           End If
       Catch ex As Exception

       End Try
   End Sub

 

In the event that the images don't display, I have manually gone to the pages which runs the above code, and I have confirmed that the code is running correctly and displaying the images.

 

Any suggestions on how to correct this problem? I think that it may be down to the size of the images, so they are causing some sort of timeout during execution of my code, but I cannot be positive.

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

Here it is:

Public Shared Function RetrievePhoto(ByVal id As String, ByVal photo As Int16, ByRef content As String) As Byte()
       Dim sqlCmd As SqlCommand
       connection = New SqlConnection(consql)

       Try
           'Open the database connection.
           If connection.State = ConnectionState.Closed Then
               connection.Open()
           End If
       Catch ex As Exception
           GoTo end1
       End Try

       Try
           myDsDataset = New DataSet
           myAdapter = New SqlDataAdapter
           Dim myDataReader As SqlDataReader = Nothing
           'Retrieve the data.
           Select Case photo
               Case 0
                   sqlCmd = New SqlCommand("SELECT (Pict1) as Pict, (Content1) as Content FROM Lands where ref = " & id & "", connection)
                   myDataReader = sqlCmd.ExecuteReader
               Case 1
                   sqlCmd = New SqlCommand("SELECT (Pict2) as Pict, (Content2) as Content FROM Lands where ref = " & id & "", connection)
                   myDataReader = sqlCmd.ExecuteReader
           End Select

           Dim myArray As Byte() = Nothing

           Do While myDataReader.Read
               If myDataReader("Pict") Is System.DBNull.Value Then
                   myArray = Nothing
                   GoTo xyz
               End If
               myArray = myDataReader.Item("Pict")
               content = myDataReader.Item("Content")
           Loop
xyz:
           'Return the data back to the user.
           Return myArray

       Catch ex As Exception
       Finally
           'Close the database connection.
           If connection.State = ConnectionState.Open Then
               connection.Close()
           End If
       End Try
end1:
   End Function

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...