Preview

Crystal Report with Image

Good Essays
Open Document
Open Document
551 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
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();

You May Also Find These Documents Helpful