内部加入多个表

时间:2013-01-21 07:51:22

标签: c# winforms crystal-reports

CrystalReportAct crt = new CrystalReportAct();
sqlcon.Open();

sql = "SELECT EmpLog.Date, JobCategory.JobDesc, 
        Client.CompDesc, Product.ProdName, EmpLog.Actions, EmpLog.Remarks 
        FROM Client 
        INNER JOIN EmpLog ON Client.CompCode = EmpLog.CompCode 
        INNER JOIN JobCategory ON EmpLog.JobCode = JobCategory.JobCode 
        INNER JOIN Product ON EmpLog.ProdCode = Product.ProdCode 
        WHERE (EmpLog.EmpID = '"+empID+"')";

SqlDataAdapter adp = new SqlDataAdapter(sql, sqlcon);
DataSet ds = new DataSet();
adp.Fill(ds, "Client");
adp.Fill(ds, "Emplog");
adp.Fill(ds, "JobCategory");
adp.Fill(ds, "Product");

crt.SetDataSource(ds);
crystalReportViewer1.ReportSource = crt;

运行但输出错误。输出几乎是80行而不是3行。

1 个答案:

答案 0 :(得分:0)

在crt.SetDataSource(ds)语句中指定表名,否则占用总行数。