在Crystal Report中,仅从For循环加载最后一条记录

时间:2012-06-21 06:47:21

标签: c# crystal-reports

我在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

1 个答案:

答案 0 :(得分: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;
相关问题