Crystal Report with Image
By: Steve • Study Guide • 315 Words • January 1, 2010 • 1,030 Views
Join now to read essay Crystal Report with Image
Create a dataset using the fields you want to display in crystal report. Define the image field as hexaBinary datatype.
Create the Crystal report using this dataset.
Now Copy this Code where you want to call the report
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;
DataSet data = new DataSet();
private void PicureFromSQLDatabase()
{
int BUFFER_LENGTH = 152768; //' chunk size
string myConnString = "SERVER=ARUN;DATABASE=Northwind;uid=sa;pwd=;";
SqlConnection cn = new SqlConnection(myConnString);
string str_query = "SELECT * FROM Categories WHERE CategoryID > 8";
SqlConnection cn1 = new SqlConnection(myConnString);
SqlDataReader reader;
SqlCommand cmd=new SqlCommand();
cn.Open();
cmd.CommandText=str_query;
cmd.Connection=cn;
reader=cmd.ExecuteReader();
data.Tables.Add();
data.Tables[0].Columns.Add("Name", System.Type.GetType("System.String"));
data.Tables[0].Columns.Add("Picture", System.Type.GetType("System.Byte[]"));
int sNo = 1;
float targetWidth = 0;
float targetHeight = 0;
float imageWidth = 0;
float imageHeight =0;
float widthRatio = 0;
float heightRatio =0;
float optimalRatio = 0;
int xImgBoundary=0;
int yImgBoundary=0;
int widthImgBoundary=0;
int heightImgBoundary=0;
byte[] bitmapData = new byte[2000];
while (reader.Read())
{
SqlCommand cmdGetPointer = new SqlCommand("SELECT @Pointer=TEXTPTR(Picture), @Length=DataLength(Picture) FROM " +
"Categories WHERE CategoryName='" + reader["CategoryName"].ToString() + "'", cn1);
SqlParameter PointerOutParam = cmdGetPointer.Parameters.Add("@Pointer", SqlDbType.VarBinary, 100);
PointerOutParam.Direction = ParameterDirection.Output;
SqlParameter LengthOutParam = cmdGetPointer.Parameters.Add("@Length", SqlDbType.Int);
LengthOutParam.Direction = ParameterDirection.Output;
cn1.Open();
cmdGetPointer.ExecuteNonQuery();
if (PointerOutParam.Value == DBNull.Value)
{
cn1.Close();
}
SqlCommand cmdReadBinary = new SqlCommand("READTEXT Categories.Picture @Pointer @Offset @Size HOLDLOCK", cn1);
SqlParameter PointerParam = cmdReadBinary.Parameters.Add("@Pointer", SqlDbType.Binary, 16);
SqlParameter OffsetParam = cmdReadBinary.Parameters.Add("@Offset", SqlDbType.Int);
SqlParameter SizeParam = cmdReadBinary.Parameters.Add("@Size", SqlDbType.Int);
SqlDataReader dr;
System.IO.FileStream fs = new System.IO.FileStream("c:abc.jpg", System.IO.FileMode.Create,