如何将 SQL 的非 Table 字段设置为 Crystal 报表设计和参数
How to set non Table field of SQL into Crystal Report Design and Parameter
我正在通过这个查询获取数据
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 table 的列 - 如何将它放入 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;
enter image description here
您错过了最后一列的名称,请尝试:
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界面的右侧面板中,只需link你的视图就可以得到一个结构。
这可以帮助你:example
我正在通过这个查询获取数据
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 table 的列 - 如何将它放入 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;
enter image description here
您错过了最后一列的名称,请尝试:
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界面的右侧面板中,只需link你的视图就可以得到一个结构。
这可以帮助你:example