2012-06-21 60 views
0

我在c#web應用程序中使用了水晶報表。有一個問題,Crystal報表從For循環加載最後一條記錄。在Crystal Report中加載僅來自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; 
    } 

如果有兩個代碼在循環顯示它只有最後一個記錄。請幫幫我。

感謝和問候...... Mitesh

回答

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; 
相關問題