Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add image to crystal report based on dataset From network path not showing proplem why

Status
Not open for further replies.

ahm1985

Programmer
Dec 6, 2012
138
0
0
EG
I need to show image in crystal report based on employee No from network path

I Create

Dataset1

DataTable1 inside Dataset1 have these fields

DriverID

DriverName

EmplyeeName

ResidentNo

and make stored procedure as

create proc ViewEmployeeNoR
(
@EmployeeNo nvarchar(20)

)
as
select * from dbo.ViewTest6 where DriverID=@EmployeeNo

and make Dataset1 as datasource of my report CrystalReportData1

and put in form crystal report viewer and textbox1 and button1

under button1 i write this code

DataTable dt = new DataTable();
string connString = "data source=192.168.1.5; initial catalog=hrdata;uid=sa; password=1234";
using (SqlConnection con = new SqlConnection(connString))
{
con.Open();
SqlCommand cmd = new SqlCommand("ViewEmployeeNoR", con);
cmd.CommandType = CommandType.StoredProcedure; // Viewxxx doesn't seem a good name for a sp
cmd.Parameters.Add("@EmployeeNo", SqlDbType.NVarChar, 20);
cmd.Parameters["@EmployeeNo"].Value = textBox1.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
}
dt.Columns.Add("Image", System.Type.GetType("System.Byte[]"));

string path = Path.Combine("\\\\192.168.1.5\\Personal Pictures", textBox1.Text) + ".jpg";
FileStream fs=null;
if (File.Exists(path))
{
fs = new FileStream("\\\\192.168.1.5\\Personal Pictures\\" + textBox1.Text + ".jpg", FileMode.Open);
}
else
{

MessageBox.Show("Please File Not Exist");

}

BinaryReader br = new BinaryReader(fs);
byte[] imgbyte = new byte[fs.Length + 1];
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));

foreach (DataRow dr in dt.Rows)
{
dr["Image"] = imgbyte;
}
ReportDocument objRpt = new Reports.CrystalReportData1();
objRpt.SetDataSource(dt);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
Report work and show all data but image not show why
what is remaining
Path i tested it work but outside crystal report
can any one help me how to add image in crystal report from local path
 
I am curious to know what type of field you used in the cr form ?

As far as I know there is nothing to show images dynamically in CR
 
What version of Visual Studio are you using and what version of the crystal SDK?

I know that the SAP Crystal Reports for Visual Studio SDK (version 13.x) that is required for VS 2010 and newer has this capability, and I think the Crystal Reports 2008 SDK for VS 2008 does as well. I'm not sure about earlier versions.

All you need is some value from the database that will help you "build" the file name for the image. So, you would do the following:

1. Place an Picture object on your report - you'll need to point this to a "dummy" image that will be displayed if the image file doesn't exist.
2. Right-click on the object and select "Format Graphic...".
3. Go to the "Picture" tab.
4. Click on the formula button to the right of "Graphic Location:"
5. Enter a formula that provides the path to and file name of the image that you want to display.

-Dell

DecisionFirst Technologies - Seven-time SAP BusinessObjects Solution Partner of the Year
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top