473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Retreiving images from SQL Express 2005

B
Hi,

Can someone help me in how I can retreive my images from my SQL DB using a
GridView or DetailsView?
I can store my image into my DB, so I would like to retreive it, but it
doesn't seem to work.
I'm using a Handler (ashx file) to retreive the image, but it doesn't seem
to work.

Here is my VB.NET code:

<%@ WebHandler Language="VB" Class="Handlerg" %>

Imports System
Imports System.IO
Imports System.Web
Imports System.Collections
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging

Public Class Handlerg
Implements IHttpHandler

Public ReadOnly Property IsReusable() As Boolean
Get
Return True
End Get
End Property

Public Shared Function GetPhoto2(ByVal BuyGroundID As Integer) As Stream
' Using
Dim connection As SqlConnection = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("IMMOASPNETDBConnectionString").ConnectionStrin g)
Try
' Using
Dim command As SqlCommand = New SqlCommand("select [Image1] FROM
[aspnet_BuyGroundImages] WHERE ([BuyGroundID]= @BuyGroundID)", connection)
Try
command.Parameters.Add(New SqlParameter("@BuyGroundID",
BuyGroundID))
connection.Open()
Dim result As Object = command.ExecuteScalar
Try
Return New MemoryStream(CType(result, Byte()))
Catch
Return Nothing
End Try
Finally
CType(command, IDisposable).Dispose()
End Try
Finally
CType(connection, IDisposable).Dispose()
End Try
End Function

Public Sub ProcessRequest(ByVal context As HttpContext)
context.Response.ContentType = "image/jpeg"
context.Response.Cache.SetCacheability(HttpCacheab ility.Public)
context.Response.BufferOutput = False
Dim id As Int32 = -1
Dim stream As Stream = Nothing
id = Convert.ToInt32(context.Request.QueryString("BuyGr oundID"))
stream = GetPhoto2(id)
Const buffersize As Integer = 1024 * 16
Dim buffer2(buffersize) As Byte
Dim count As Integer = stream.Read(buffer2, 0, buffersize)
While count > 0
context.Response.OutputStream.Write(buffer2, 0, count)
count = stream.Read(buffer2, 0, buffersize)
End While
End Sub
End Class

Thanks for all your help....
Bart
Dec 23 '05 #1
0 957

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lubomir | last post by:
Hi, I would like to ask, how different are C# 2005 Express Edition and C# within MS Visual Studio 2005. Than as well Visual Web Developer 2005 Express Edition and ASP within MS VS 2005. ...
5
by: wschlichtman | last post by:
I have an application that allows users to view images and hear sound files. The images and soundclips are stores in a SQL database in image fields. Originally, I transferred the data from an...
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
8
by: Peter Oliphant | last post by:
I have been using VS C++.NET 2005 Express as our company waits for the MSDN full version to arrive. It is a pretty amazing free tool! My question is I'd like to also do some VS C#.NET stuff too....
1
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005...
5
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page...
11
by: HC | last post by:
I posted this in one of the VB forums but I'm starting to think it might be more appropriate to have it here, since it really seems to be a SQL server (MSDE/Express 2005) problem: Hey, all, I...
3
by: Steve | last post by:
Hi All I downloaded Sql server 2005 express SP2 and attempted to modify the Bootstrapper package files as I did with SP1 When i try to install SQL server as part of my VS 2005 deployment app I...
1
by: pompair | last post by:
Hi, Could someone give a pointer how to import couple of hundred images into Sql Server 2005 Express Edition database? Is there a tool for it? Can it be done with Sql Management Studio or is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.