Loading and Inserting Blob Data Types using LINQ to SQL in ASP.NET using C#

I would like to know how i can use LINQ to store blob data types. I basically want to store binary data files like documents in an sql server database. i have done this the traditional was using SQL but i'm not sure whether LINQ supports it.

Any pointers please?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think you can do that using byte[].
I am sorry i do not have VS right now to test it.

see if this helps you

Thanks and regards,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AshokSr. Software EngineerCommented:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Drawing.Imaging;
using System.Configuration;


    SqlConnection conn;
    string sConnStr;
    sConnStr = "Set your Connection String here...........";

        conn = new SqlConnection(sConnStr);
        string sSQL = "UPDATE tbSomeTable SET Image = (@BlobData) " +
                      "where GroupID = " + txtGrpID.Text.Trim() +
                      " and ItemID =  " + txtItemID.Text.Trim();
        //SqlCommand cmd = new SqlCommand("INSERT INTO BLOBTest (BLOBData) VALUES (@BLOBData)", conn);
        SqlCommand cmd = new SqlCommand(sSQL, conn);
        String strBLOBFilePath;
        openFileDialog1.Title = "Select an Image";
        openFileDialog1.Filter = "Icons|*.ico|Bitmap|*.bmp|JPEG|*.jpg|GIF Images|*.gif|PNG Images|*.png";
        openFileDialog1.FileName = "";
        if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
          strBLOBFilePath = @"C:\MyImage.ICO";//Modify this path as needed.
          strBLOBFilePath = @openFileDialog1.FileName;
        //Read jpg into file stream, and from there into Byte array.
        FileStream fsBLOBFile = new FileStream(strBLOBFilePath, FileMode.Open, FileAccess.Read);
        Byte[] bytBLOBData = new Byte[fsBLOBFile.Length];
        fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);

        //Create parameter for insert command and add to SqlCommand object.
        SqlParameter prm = new SqlParameter("@BLOBData", SqlDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, false,
              0, 0, null, DataRowVersion.Current, bytBLOBData);

        //Open connection, execute query, and close connection.
      catch (Exception ex)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.