0

我在 C# Web 应用程序中使用水晶报表。水晶报告从 For 循环加载最后一条记录存在问题。

我将产品代码作为代码存储在for循环中。并根据该单个或多个代码,水晶报告显示信息。那个产品。

我用....

for (int i = 0; i < code.Length; i++)
    {
        string str = "select crbal*-1 as crbal, glname, contprsn, refby, glphone1, glcity, glphone2, email, crlimit, restorddueamt  from db1.dbo.glmast WHERE drgroup='A3402' and crbal<>0 and glcode="+code[i]+ "";

        SqlDataAdapter ad = new SqlDataAdapter(str, con2);
        DataSet ds = new DataSet();
        ad.Fill(ds);

        path = Server.MapPath("ERP_REPORT_MAIN.rpt");
        cr = new ReportDocument();
        cr.Load(path);

        cr.SetDataSource(ds.Tables[0]);
        CrystalReportViewer1.ReportSource = cr;
    }

如果,for 循环中有两个代码,它只显示最后一条记录。请帮我。

谢谢和问候... Mitesh

4

1 回答 1

0

我会修改代码,并做一些轻微的效率改进:

string query = "select crbal*-1 as crbal, glname, contprsn, refby, glphone1, glcity,    glphone2, email, crlimit, restorddueamt  from db1.dbo.glmast WHERE drgroup='A3402' and crbal<>0 and glcode in (

for (int i = 0; i < code.Length; i++)
{
    query += code[i];
    if (i != code.Length -1)
        query += ","
    else
        query += ")";
}

SqlDataAdapter ad = new SqlDataAdapter(str, con2);
DataSet ds = new DataSet();
ad.Fill(ds);

path = Server.MapPath("ERP_REPORT_MAIN.rpt");
cr = new ReportDocument();
cr.Load(path);

cr.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = cr;
于 2012-06-21T07:35:18.413 回答