473,405 Members | 2,187 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,405 software developers and data experts.

Reading Blobs from SQL and using it in an Image control of a webfo

Please This is queit a task av been trying to solve. Could anyone please tell
me how to read a blob from an SQL using a dataset and stuffing this image
into the Image control of a webform.
Any suggetion that would help would be highly appreciated.
--
Iyke
Mar 19 '06 #1
9 1833
This is an example of the Page_Load event of a page GetImage.aspx:

protected void Page_Load(object sender, System.EventArgs e)
{
// get image id
string imageId = this.Request.Params["id"];

System.Data.SqlTypes.SqlBinary image; // image from database
string sql = String.Format ("SELECT photo FROM customers WHERE
customer_id = {0}", imageId);

// get image from database
SqlConnection conn = new SqlConnection (myConnectionString);
SqlCommand com = new qlCommand (sql, conn);
conn.Open();
try
{
SqlDataReader reader = dba.RunSelect (sql);
reader.Read ();
image = reader.GetSqlBinary(0);
reader.Close ();
}
finally
{
conn.Close ();
}

if (!image.IsNull && image.Value.Length != 0)
{
// stream image down to client
this.Response.ContentType = "image/gif";
this.Response.BinaryWrite (image.Value);
}
}

You would use this page as an url for your image control in format
"GetImage.aspx?id=xx".

Eliyahu

"JuniorProgrammer" <tr****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
Please This is queit a task av been trying to solve. Could anyone please
tell
me how to read a blob from an SQL using a dataset and stuffing this image
into the Image control of a webform.
Any suggetion that would help would be highly appreciated.
--
Iyke

Mar 19 '06 #2
On Sun, 19 Mar 2006 02:39:13 -0800, JuniorProgrammer wrote:
Any suggetion that would help would be highly appreciated.


I suggest NOT using the database to store images, unless they're fairly
small ones. Instead, store the image on the disk, and store a filename
pointer to it in the database. This will make your database smaller, less
prone to fragmentation, and reduce the bandwidth being consumed by record
requests.

In my opinion, storing images in databases takes far more resources than
storing them in the file system.
Mar 19 '06 #3
Often, security considerations make using database mandatory.

Eliyahu

"Erik Funkenbusch" <er**@despam-funkenbusch.com> wrote in message
news:6t***************@funkenbusch.com...
On Sun, 19 Mar 2006 02:39:13 -0800, JuniorProgrammer wrote:
Any suggetion that would help would be highly appreciated.


I suggest NOT using the database to store images, unless they're fairly
small ones. Instead, store the image on the disk, and store a filename
pointer to it in the database. This will make your database smaller, less
prone to fragmentation, and reduce the bandwidth being consumed by record
requests.

In my opinion, storing images in databases takes far more resources than
storing them in the file system.

Mar 19 '06 #4
On Sun, 19 Mar 2006 17:21:11 +0200, Eliyahu Goldin wrote:
Often, security considerations make using database mandatory.


That doesn't make any sense. Any security consideration you can put in
place via SQL can be put in place using file permissions.
Mar 19 '06 #5
In SQL Server you can setup security rights for sql logons and roles. File
permissions can be granted to windows accounts, not to sql ones.

Eliyahu

"Erik Funkenbusch" <er**@despam-funkenbusch.com> wrote in message
news:f8***************@funkenbusch.com...
On Sun, 19 Mar 2006 17:21:11 +0200, Eliyahu Goldin wrote:
Often, security considerations make using database mandatory.


That doesn't make any sense. Any security consideration you can put in
place via SQL can be put in place using file permissions.

Mar 19 '06 #6
On Sun, 19 Mar 2006 18:05:20 +0200, Eliyahu Goldin wrote:
In SQL Server you can setup security rights for sql logons and roles. File
permissions can be granted to windows accounts, not to sql ones.


Windows also has security rights and roles. Again, anything you can define
in SQL can be defined in Windows as well. If you're stuck on using SQL for
your security, it's pathetically easy to validate security through SQL to
access files on the hard disk.

Security is not a valid reason in my opinion.
Mar 19 '06 #7

"Eliyahu Goldin" <re*************@monarchmed.com> wrote:
Often, security considerations make using database mandatory.


Well, even more often the database could be accessed across domains, and
through different applications (or application layers) that does not allow
the use of a std. filesystem access.
- in that case the Database seems the more flexible choice.

R-)
Mar 19 '06 #8
Security considerations notwithstanding,
here is an alternative method for reading and displaying images as you
describe without the need for an external handler (e.g., get them directly
out of the same DataSet your other data is in):

http://www.eggheadcafe.com/articles/20050911.asp

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"JuniorProgrammer" wrote:
Please This is queit a task av been trying to solve. Could anyone please tell
me how to read a blob from an SQL using a dataset and stuffing this image
into the Image control of a webform.
Any suggetion that would help would be highly appreciated.
--
Iyke

Mar 19 '06 #9
I want to thank you all for ur replies. Every contribution made good sence,
even broadens my idea of the issue.

Thank you very much one and all.
Mar 20 '06 #10

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

Similar topics

0
by: omkar prabhu | last post by:
i am using postgres 7.0.3 and also postgres 7.2.1 I am new towards using blobs,I want to transfers records with blobs from a table to different database(postgres) using perl without extracting...
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
1
by: mb345345 | last post by:
Hi group, I have a nice little CMS application which has been running for quite some time storing content in blobs in sql (the 'image' datatype) and spitting them out to a frame in the browser via...
2
by: Ed | last post by:
Hope someone can help me out... I have been tasked to read some image data from an sql database and save the files to flat files. OK, sounds easy as I'v used BLOBs before. But this is an old...
2
by: Connie | last post by:
We have a blob in one table that is storing pdf files. I need to write a select query that will grab that column and write those *.pdf files out to a location on my hard drive. Does anyone know...
1
by: sylwiq | last post by:
I am using DB2 and it's Image Extender to query database by image content. When using Tomcat and jsp (JDBC driver) everything works, but when using PHP and Apache - queries by content do not work....
5
by: bhodgins | last post by:
Hi, I am new on here, and had a newbie question that I am stumped with. I am not new to access, but am new to VB. I am trying to export BLOBs from a field called photo to external jpeg files. I...
2
by: kentgorrell | last post by:
I had a wonderful time working out how to read and write BLOBs using GetChunk until I found the new streaming object in ADO 2.6 very easy. Now I am confronted with DIBs The code I have is VB6 but...
4
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Hi all another LINQ question!! to retrieve and display sql varbinary images I currently use the following code: Imports System.Data.SqlClient Imports System.Drawing Imports...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
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 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.