简体   繁体   中英

How to display image from database (stored as BLOB), if the image ID is not known?

I've got an SQL Server database, which has a table containing a number of fields - one of which is called 'Image', of type varbinary(MAX) . There is no 'ImageID' field, and thus I presume I am unable to use an ashx page to be able to display the image in an asp:Image control (as explained in numerous guides).

What approach should I take for displaying the image? I have to use a blob by force, and cannot add an 'ImageID' field, due to strict requirements.

Any ideas?

Why do you need ImageID? Any "Image" in an given row is identified table primary key. In the examples, it must be ImageID. In your case, use the primary key

One of the best guides I've seen in Remus Rusanu's "Download and Upload images from SQL Server via ASP.Net MVC"

Don't know and haven't seen the guides you are talking about, but I'm making a guess, that those samples pass ImageID to ashx and then retrieve BLOB from database by using this ImageID as criteria in SQL statement.

So you can do something similar, just by using some other identifier instead of ImageID like, RecordId or something other you have in your table. Just make sure, that this column is unique identifier for given row.

Probably you just need to use primary key column of this table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM