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 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