Not sure if this is belongs here, or maybe in SQL...
I have a SQL Server 2005 database where I store a varbinary(MAX)
field. In my Web form, I allow the user to upload a photo to the
database. It's stored in the varbinary field.
I used an HTTP handler to display the image in an HTML image control
on a FormView. I have a button that allows the user to delete the
photo from the database.
This button runs "UPDATE table SET photo=NULL" on the database. That
works fine, the field is set to NULL in the database. However,
whenever I select the record in the FormView from which I deleted the
photo, the html Image control is still the same size as it was when
the photo was in there. The photo is gone, and it gives the "alt"
text, but the control is still big. It persists even when I exit and
re-enter my app. Is there something I have to do to the control, or
the database field, to shrink it back down to original size? 7 7959
On Sep 12, 7:55 pm, gsauns <gsa...@gmail.comwrote:
Not sure if this is belongs here, or maybe in SQL...
I have a SQL Server 2005 database where I store a varbinary(MAX)
field. In my Web form, I allow the user to upload a photo to the
database. It's stored in the varbinary field.
I used an HTTP handler to display the image in an HTML image control
on a FormView. I have a button that allows the user to delete the
photo from the database.
This button runs "UPDATE table SET photo=NULL" on the database. That
works fine, the field is set to NULL in the database. However,
whenever I select the record in the FormView from which I deleted the
photo, the html Image control is still the same size as it was when
the photo was in there. The photo is gone, and it gives the "alt"
text, but the control is still big. It persists even when I exit and
re-enter my app. Is there something I have to do to the control, or
the database field, to shrink it back down to original size?
Do you use width/height there?
<asp:Image width=... height=...
No, I am not using width/height.
It is not an ASP image control, it's the HTML control. I couldn't
acheive the same functionality with the ASP control, since i am
filling in the image control with context.Response.OutputStream.Write
in the handler. Running the HTML control server-side doesn't work
either, as it won't display the image. So I can't manipulate it thru
code.
When I go to a new record (that doesn't contain a photo), the image
control is sized just fine. But going back to the same record, it gets
big again.
On Sep 12, 8:45 pm, gsauns <gsa...@gmail.comwrote:
No, I am not using width/height.
It is not an ASP image control, it's the HTML control. I couldn't
acheive the same functionality with the ASP control, since i am
filling in the image control with context.Response.OutputStream.Write
in the handler. Running the HTML control server-side doesn't work
either, as it won't display the image. So I can't manipulate it thru
code.
When I go to a new record (that doesn't contain a photo), the image
control is sized just fine. But going back to the same record, it gets
big again.
hm, it sounds strange, maybe it is something with the cache? Try to
clean it or try to see if Firefox has the same behavior
On Sep 12, 2:59 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Sep 12, 8:45 pm, gsauns <gsa...@gmail.comwrote:
No, I am not using width/height.
It is not an ASP image control, it's the HTML control. I couldn't
acheive the same functionality with the ASP control, since i am
filling in the image control with context.Response.OutputStream.Write
in the handler. Running the HTML control server-side doesn't work
either, as it won't display the image. So I can't manipulate it thru
code.
When I go to a new record (that doesn't contain a photo), the image
control is sized just fine. But going back to the same record, it gets
big again.
hm, it sounds strange, maybe it is something with the cache? Try to
clean it or try to see if Firefox has the same behavior
Clearing the cache doesn't do anything.
Firefox does NOT have the same behavior, because IE displays the small
"X" along with the image frame and the alt text, where Firefox just
displays the alt text... could be an IE quirk? Installing Firefox on
all clients' machines is not a viable solution for me, I wish I could
just figure it out. Thanks for your help.
How do you upload / download your images from your SQL database?
That could be where your problem is.
Try this article http://aspnet.4guysfromrolla.com/articles/120606-1.aspx
for a very good method to store and display binary files.
Let me know how you get on.
Hope this helps.
James
On Sep 12, 9:29 pm, gsauns <gsa...@gmail.comwrote:
On Sep 12, 2:59 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Sep 12, 8:45 pm, gsauns <gsa...@gmail.comwrote:
No, I am not using width/height.
It is not an ASP image control, it's the HTML control. I couldn't
acheive the same functionality with the ASP control, since i am
filling in the image control with context.Response.OutputStream.Write
in the handler. Running the HTML control server-side doesn't work
either, as it won't display the image. So I can't manipulate it thru
code.
When I go to a new record (that doesn't contain a photo), the image
control is sized just fine. But going back to the same record, it gets
big again.
hm, it sounds strange, maybe it is something with the cache? Try to
clean it or try to see if Firefox has the same behavior
Clearing the cache doesn't do anything.
Firefox does NOT have the same behavior, because IE displays the small
"X" along with the image frame and the alt text, where Firefox just
displays the alt text... could be an IE quirk? Installing Firefox on
all clients' machines is not a viable solution for me, I wish I could
just figure it out. Thanks for your help.- Hide quoted text -
- Show quoted text -
I think it would be good if you can give us an example of your code.
I'll try to check it. Thanks
Thanks guys. See anything here?
Here's the image control in the FormView:
<img id="imgPhoto" alt="No photo." src='ImageHandler.ashx?contactID=<
%# Eval("contact_id") %>' />
Here is uploading the binary data:
public void formviewContacts_OnInserting(object sender,
SqlDataSourceCommandEventArgs e)
{
int intLen =
((FileUpload)formviewContacts.FindControl("fileIma ge")).PostedFile.ContentLength;
byte[] bytImage = new byte[intLen];
if
(((FileUpload)formviewContacts.FindControl("fileIm age")).HasFile)
{
Response.Write(bytImage.Length.ToString());
((FileUpload)formviewContacts.FindControl("fileIma ge")).PostedFile.InputStream.Read(bytImage,
0, intLen);
SqlParameter param = new SqlParameter("@image",
SqlDbType.VarBinary);
param.Direction = ParameterDirection.InputOutput;
param.Value = bytImage;
e.Command.Parameters.Add(param);
}
}
....And here is my Handler class:
<%@ WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.IO;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public class ImageHandler : IHttpHandler {
public bool IsReusable {
get {
return true;
}
}
public static Stream GetPhoto2(int photoid)
{
using (SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["ConnectionString"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("SELECT [Photo]
FROM [Contact] WHERE [contact_id]=@id", connection))
{
command.Parameters.Add(new SqlParameter("@id", photoid));
connection.Open();
object result = command.ExecuteScalar();
try
{
return new MemoryStream((byte[])result);
}
catch
{
return null;
}
}
}
}
public void ProcessRequest (HttpContext context)
{
//Set up the response settings
context.Response.ContentType = "image/jpeg";
context.Response.Cache.SetCacheability(HttpCacheab ility.Public);
context.Response.BufferOutput = false;
// Setup the PhotoID Parameter
Int32 id = -1;
Stream stream = null;
id = Convert.ToInt32(context.Request.QueryString["contactID"]);
stream = GetPhoto2(id);
const int buffersize = 1024 * 16;
byte[] buffer2 = new byte[buffersize];
int count = stream.Read(buffer2, 0, buffersize);
while (count 0) {
context.Response.OutputStream.Write(buffer2, 0, count);
count = stream.Read(buffer2, 0, buffersize);
}
}
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sanju |
last post by:
Dear All,
I have written a stored procedure which returns a
Varbinary column from MS SQl Server 7 database. I tried
converting the same into Varchar but this will not work in
the database. I...
|
by: Eugene |
last post by:
Hi,
I have been battling with this for days now. If you execute the SQL below
you will get the following result: 0x3078303030303030, which is incorrect.
It looks like the conversion is more...
|
by: Maciej |
last post by:
Hello I have some problems with converting varbinary to float in T-SQL
stored procedure. In my C# application i have table of structures with
double type fields. Size of this table is variant. I...
|
by: Vinod |
last post by:
Hi,
I have a stored procedure which expects a varbinary datatype. How
can i pass a varbinary datatype from asp.net
directly to the stored procedure. I tried using the Convert function in Sql...
|
by: Bill Nguyen |
last post by:
I need sample code to insert binary file (mappoint map file) into a
varbinary column using VB.NET.
Please help!
Thanks
Bill
| |
by: =?Utf-8?B?ZHZhcm1h?= |
last post by:
Hi
I am executing a Sql Server SP from my C# app
One of the parameters is of type varbinary. Since the content length of this
parameter is variable I cannot set it to a pre-defined length. What...
|
by: Karch |
last post by:
I am doing some experimenting with serialization (for use with Service
Broker) and I am having a problem converting from a .NET DateTime (in the
client application) to a SqlDbType.VarBinary (as...
|
by: Gilad |
last post by:
Hi
I moved to SQL Server 2005 (from 2000) and noticed there is a better
variable to deal with binary arrays.
I hava a table that hold 9 columns of images (BLOB). each array has a
different size...
|
by: Martin Horst |
last post by:
Hi,
I've got an application which is written in .Net 1.1. When I try to
write a varbinary(max) field using the SqlCommand and SqlParameter
classes I got an exception like this:
"The...
|
by: dbudry |
last post by:
I have a program that I developed that builds an XML file that stores base64binary data from images stored in SQL Server. The XML file along with the schema get transfered, then another program...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |