Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is it possible to retrieve/insert a picture into a MS SQL Database as a BLOB and display as a datagrid background or image. I've found plenty of examples using SELECT and INSERT but none using Stored Procedures.

I usually retrieve/update the data in the following way:

C#
DataContext db = new DataContext();
var q1 = db.LP_List_Active_Entities(1,1,0);
DropDownName.DataSource = q1;
DropDownName.DataBind();

var q2 = db.LP_Automated_Entity_Detection(User.Identity.Name, Convert.ToBoolean(true));
DropDownName.SelectedValue = q2.First().entityid.ToString();


Is it possible to do something similar without using SELECT and INSERT.

This is for C# and displayed in asp.net

The connection and available Stored Procedures are saved in my connection.dbml file
Posted
Updated 30-Oct-11 1:31am
v2

1 solution

It has nothing to do with a stored procedure: the data is retuned as a stream of bytes whether from an SP or a SELECT query.

The work is in doing the display. Here is a generic class which shows one way to do it: A generic Image-From-DB class for ASP.NET[^]
 
Share this answer
 
Comments
Wayne Evans 30-Oct-11 8:54am    
Thanks. I am trying to keep it simple and just pass parameters to a SP like my example above. I don't want the possibility as SQL injection issues, which is my objection for using SELECT and INSERT. The code in the SP will be something like

<pre lang="SQL">select image from customer where id = @parameter</pre>

Is there a way I can use your code, but specify a SP instead of a SELECT?
OriginalGriff 30-Oct-11 12:13pm    
Yes - it works exactly the same, you just have to specify a procedure type as the command. But, is there a lot of point in having an SP to do the job, when it is less code in total to do the command directly? That just adds another layer of "things that could go wrong" without adding any real value that I can see.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900