ReviewEssays.com - Term Papers, Book Reports, Research Papers and College Essays
Search

Crystal Report with Image

Essay by   •  December 9, 2010  •  Study Guide  •  315 Words (2 Pages)  •  1,334 Views

Essay Preview: Crystal Report with Image

Report this essay
Page 1 of 2

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, System.IO.FileAccess.Write);

int Offset = 0;

OffsetParam.Value = Offset;

byte[] Buffer;

Buffer = new byte[BUFFER_LENGTH - 1];

while (Offset < (int)LengthOutParam.Value)

{

PointerParam.Value = PointerOutParam.Value;

if ((Offset + BUFFER_LENGTH) >= (int)LengthOutParam.Value)

{

SizeParam.Value = (int)LengthOutParam.Value - Offset;

}

else

{

SizeParam.Value

...

...

Download as:   txt (4.7 Kb)   pdf (85.9 Kb)   docx (11 Kb)  
Continue for 1 more page »
Only available on ReviewEssays.com