I have a binary file which stores in the customerPicture
column that has Image as a datatype in the CUSTOMERs table.
I have saved an image by using this line of code in LINQ to SQL.
Dim db = new MyCompanyDataContext
Dim newCus = new CUSTOMERs
Dim filebyte As Byte() = fileUploader.FileBytes
Dim fileBinary As New System.Data.Linq.Binary(filebyte)
newCus.customerPicture = fileBinary
Then now I want to retrieve this binary file to bind in the gridview in ASP.NET by using LINQ to SQL, but I don't know how. Can you please show me some ways to reach the solution?
Best Answer
you can use Httphandler to retrive the images from the database.
If you have a Image as an ItemTemplate in the datagrid.
In the ItemDataBound event of the datagrid call the "HttpHandler" to display the image.In the below code I am finding the image control and assinging the imageUrl as the HttpHandler file path.I am also passing the id as querystring to the HttpHandlerFile.
And in the HttpHandler file use Linq to retrive the Image and display it.
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "image/jpeg";
As this HttpHandler file is mapped to the imageURL in the datagrid , you can see the images displayed in the datagrid.