how can get the image from sqlserver Db into my report. RRS feed

  • Question

  • Hi,

    I want to get the Jpeg image in my report.

    Where i'll be having the folder path of the image in the table.

    help me out in solving this.


    Tuesday, March 15, 2011 6:43 AM


  • Hello Arsath,


    Welcome to the MSDN Forum and thanks for posting here.

    We can write a binary large object (BLOB) to a database as either binary or character data, depending on the type of field at the data source. BLOB is a generic term that refers to the text, ntext, and image data types, which typically contain documents and pictures.

    To write a BLOB value to the database, issue the appropriate INSERT or UPDATE statement and pass the BLOB value as an input parameter. If the BLOB is stored as text, such as a SQL Server text field, we can pass the BLOB as a string parameter. If the BLOB is stored in binary format, such as a SQL Server image field, we can pass an array of type byte as a binary parameter.

    The following code example adds employee information to the Employees table in the Northwind database. A photo of the employee is read from a file and added to the Photo field in the table, which is an image field.


            public static void AddEmployee(string lastName,string firstName,string title,

                DateTime hireDate,int reportsTo,string photoFilePath,string connectionString)


                byte[] photo = GetPhoto(photoFilePath);


                using (SqlConnection connection = new SqlConnection(



                    SqlCommand command = new SqlCommand(

                      "INSERT INTO Employees (LastName, FirstName, " +

                      "Title, HireDate, ReportsTo, Photo) " +

                      "Values(@LastName, @FirstName, @Title, " +

                      "@HireDate, @ReportsTo, @Photo)", connection);



                       SqlDbType.NVarChar, 20).Value = lastName;


                        SqlDbType.NVarChar, 10).Value = firstName;


                        SqlDbType.NVarChar, 30).Value = title;


                         SqlDbType.DateTime).Value = hireDate;


                        SqlDbType.Int).Value = reportsTo;



                        SqlDbType.Image, photo.Length).Value = photo;







            public static byte[] GetPhoto(string filePath)


                FileStream stream = new FileStream(

                    filePath, FileMode.Open, FileAccess.Read);

                BinaryReader reader = new BinaryReader(stream);


                byte[] photo = reader.ReadBytes((int)stream.Length);





                return photo;



    Related Threads:


    Have a nice day,

    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 17, 2011 6:16 AM