0

我想在 RDLC 报告中显示新列“总计”,实际上用于计算总计的字段是不同的数据集。我创建了一个数据表并将我想在报告中显示的字段(包括“总计”)插入其中。当我执行程序时,错误显示“关键字'WHERE'附近的语法不正确。

string sql = "SELECT customer.customer, 
                     customer.imp_license_no, 
                     customer.psq_level,           
                     whbal.std_weight, 
                     whbal.qty_good,  
                     whbal.qty_slack, 
                     total FROM (
              SELECT((qty_good+qty_slack)*std_weight/1000) AS Total FROM whbal 
              WHERE warehouse='SKW') customer 
              INNER JOIN whbal 
              WHERE customer.customer=whbal.customer AND customer.customer BETWEEN @cust1 AND @cust2";

        SqlCommand custcom = new SqlCommand(sql, myconnection);

        custcom.Parameters.AddWithValue("@cust1", cboFrom.SelectedValue.ToString());
        custcom.Parameters.AddWithValue("@cust2", cboTo.SelectedValue.ToString());

        SqlDataAdapter da = new SqlDataAdapter(custcom);
        DataSet1 ds = new DataSet1();
        da.Fill(ds, "customer1");
        da.Fill(ds, "whbal");

        myconnection.Close();

        reportViewer1.Reset();
        reportViewer1.LocalReport.ReportEmbeddedResource = "WindowsFormsApplication1.Report1.rdlc";
        reportViewer1.ProcessingMode = ProcessingMode.Local;

        reportViewer1.LocalReport.DataSources.Clear();
        reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", ds.Tables["Customer1"]));
        reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1",ds.Tables["whbal"]));

        reportViewer1.RefreshReport();

有谁知道是什么问题,请帮忙评论。提前致谢

4

1 回答 1

6

你不应该使用ONINNER JOIN

INNER JOIN whbal ON customer.customer = whbal.customer AND 
                    customer.customer BETWEEN @cust1 AND @cust2";
于 2013-10-30T03:09:03.073 回答