Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using stored procedure for fetching data from table. photo field save in my DB as Image datatype, when debug datatable show photo as system.byte[], and design time crystal report preview show photo, but after execution of application photo not show on report.
How can photo show on report. please Help me.

What I have tried:

Report Viewer Form Code:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ID_Card
{
public partial class Form1 : Form
{
emp OBJemp = new emp();
public Form1()
{
InitializeComponent();
}
private string _employeeId;

public string employeeId
{
get { return _employeeId; }
set { _employeeId = value; }
}
private void Form1_Load(object sender, EventArgs e)
{
DataTable DT = new DataTable();
DT = OBJemp.CreateTempTable(OBJemp.Get_report(employeeId));
StudentIdCard crspt = new StudentIdCard();
crspt.Database.Tables[0].SetDataSource(DT);
crystalReportViewer1.ReportSource = crspt;
crystalReportViewer1.Zoom(1);
}

private void crystalReportViewer1_Load(object sender, EventArgs e)
{
this.crystalReportViewer1.RefreshReport();
}
}
}

Print Button Code:-

string EmployeeId = "";
private void btnReport_Click(object sender, EventArgs e)
{
EmployeeId = "";
foreach (DataGridViewRow r in dgvEmp.Rows)
{
if (r.Cells[0].Value != null)
{
if (r.Cells[0].Value.ToString().ToUpper() == "TRUE")
{
EmployeeId = EmployeeId + "," + r.Cells[1].Value;
}
}

}
Form1 frm = new Form1();

frm.employeeId = EmployeeId;
frm.Show();



Get_Report Function:-

public SqlDataReader Get_report(string EmployeesID)
{
SqlParameter[] pram = new SqlParameter[2];
pram[0] = new SqlParameter("@type", 8);
pram[1] = new SqlParameter("@EmployeeId", EmployeesID);
return SqlHelper.ExecuteReader(Constr, "IDCard", CommandType.StoredProcedure, pram);

}


Stored Procedure :-

ALTER PROCEDURE [dbo].[IDCard]
@EmployeeName NVARCHAR(50) = NULL
,@EmployeeId NVARCHAR(1000) = NULL
,@CompCode NVARCHAR(3) = NULL
,@BloodGroup NVARCHAR(3) = NULL
,@DepartmentCode NVARCHAR(50) = NULL
,@photo image=null
,@TermDate DateTime = NULL
,@DOB DateTime = NULL
,@type INT = 1
,@ID INT = 1

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

IF (@type = 1)
BEGIN
SELECT EmployeeId
,Case [CompCode]
WHEN 01
THEN 'OP'
ELSE
'NC'
END As Company
,EmployeeName
,BloodGroup
,DepartmentCode
,TermDate
,DOB
,EmployeeCode
FROM Master_Employee where TermDate IS NULL order by 1 desc

END

ELSE IF (@type = 2)
BEGIN
select distinct CompCode, Case [CompCode]
WHEN 01
THEN 'OP'
ELSE
'NC'
END As Org
from Master_Employee
END
ELSE IF (@type = 3)
BEGIN
SELECT
EmployeeId
,Case [CompCode]
WHEN 01
THEN 'OP'
ELSE
'NC'
END As Company
,EmployeeName
,BloodGroup
,DepartmentCode
,TermDate
,DOB
FROM Master_Employee where TermDate IS NULL and EmployeeId =@EmployeeId and CompCode =@CompCode
END
ELSE IF (@type = 4)
BEGIN
SELECT
EmployeeId
,Case [CompCode]
WHEN 01
THEN 'OP'
ELSE
'NC'
END As Company
,EmployeeName
,BloodGroup
,DepartmentCode
,TermDate
,DOB
FROM Master_Employee where TermDate IS NULL and EmployeeId =@EmployeeId

END
ELSE IF (@type = 5)
BEGIN
SELECT
EmployeeId
,Case [CompCode]
WHEN 01
THEN 'OP'
ELSE
'NC'
END As Company
,EmployeeName
,BloodGroup
,DepartmentCode
,TermDate
,DOB
FROM Master_Employee where TermDate IS NULL and CompCode=@CompCode

END
ELSE IF (@type = 6)
BEGIN
SELECT
EmployeeId
,Case [CompCode]
WHEN 01
THEN 'OP'
ELSE
'NC'
END As Company
,EmployeeName
,BloodGroup
,DepartmentCode
,TermDate
,DOB
FROM Master_Employee where TermDate IS NULL and EmployeeName like ''+@EmployeeName+ '%'

END

ELSE IF (@type = 7)
BEGIN
SELECT
EmployeeId
,Case [CompCode]
WHEN 01
THEN 'OP'
ELSE
'NC'
END As Company
,EmployeeName
,BloodGroup
,DepartmentCode
,TermDate
,DOB
FROM Master_Employee where TermDate IS NULL and CompCode=@CompCode and EmployeeName like ''+@EmployeeName+'%'


END
ELSE IF (@type = 8)
BEGIN



SELECT e.EmployeeCode
,e.EmployeeId
,e.EmployeeName,Case CompCode
WHEN 01
THEN 'OP'
ELSE
'NC'
END As Company, e.EmployeeId +'/'+ Case CompCode
WHEN 01
THEN 'OP'
ELSE
'NC'
END as EmpID , e.BloodGroup, e.DOB ,e.TermDate ,p.Photo from Master_Employee e left join Master_EmployeePhoto p on
(e.EmployeeCode =p.EmployeeCode ) where TermDate IS NULL and EmployeeId in( Select * from dbo.BreakStringIntoRows(@EmployeeId))

END

END
Posted
Updated 26-Dec-19 18:58pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900