C# 如何在Crystal报表设计和参数中设置SQL的非表字段

C# 如何在Crystal报表设计和参数中设置SQL的非表字段,c#,sql,winforms,crystal-reports,desktop-application,C#,Sql,Winforms,Crystal Reports,Desktop Application,我正在通过此查询获取数据 select employee.empcode, employee.fullname, count(attendance.Status) from employee inner join attendance on employee.empcode = attendance.EmpCode group by employee.empcode, employee.fullname order by empl

我正在通过此查询获取数据

select 
    employee.empcode, employee.fullname,
    count(attendance.Status) 
from 
    employee 
inner join 
    attendance on employee.empcode = attendance.EmpCode 
group by 
    employee.empcode, employee.fullname 
order by 
    employee.empcode

但是(没有列名)不是我的SQL表的列-如何将其放入Crystal报表设计和代码中

rptAttendance rpt = new rptAttendance();

SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand MyCommand = new SqlCommand();
SqlDataAdapter myDA = new SqlDataAdapter();
DataSet myDS = new DataSet();

MyCommand.Connection = myConnection;
MyCommand.CommandText = "select employee.empcode, employee.fullname , COUNT(attendance.Status) from employee inner join attendance on employee.empcode = attendance.EmpCode group by employee.empcode, employee.fullname order by employee.empcode";
MyCommand.CommandType = CommandType.Text;

myDA.SelectCommand = MyCommand;
myDA.Fill(myDS, "Attendance");
myDA.Fill(myDS, "Employee");

rpt.SetDataSource(myDS);
CrystalReportViewer1.ReportSource = rpt;


如果缺少最后一列的名称,请尝试使用:

select employee.empcode, employee.fullname , COUNT(attendance.Status) countColumn from employee inner join attendance on employee.empcode = attendance.EmpCode group by employee.empcode, employee.fullname order by employee.empcode
编辑:将结构添加到报告中

我通常创建一个假视图,如:

create view fakeView as
select convert(nvarchar(yourrealColumnLength) '') columnName,
       convert(int, 0) column2Name
       .......
然后在crystal界面的右侧面板中,只需链接视图即可获得结构


这可能会帮助您:

但是如何在crystal Report的designview中添加?就像该报告的任何其他列一样query@MuhammadZohaib你为其他人做了些什么?我通常是通过创建一个带有列名和数据类型的假视图并将其传递到报表资源中来实现的,我还将使用this@GuidoG先生,crystal report中没有可添加此字段的字段将您的列命名为@claud.io此处建议您应修复所有问题。然后,您可以像添加所有其他列一样添加到报告中