2014-04-06 1 views
1

나는 데이터 테이블로 된 DataGridView의 데이터 소스를 얻을보고서 뷰어에서 DataTable의 데이터를 사용하는 방법은 무엇입니까?

 DataTable dd = (DataTable)DGVCars.DataSource; 
     dd.TableName = "Cars"; 
     Report r = new Report(dd); 
     r.Show(); 

 // MaterialsSuppliersDataSet t = new MaterialsSuppliersDataSet(); 

     // MessageBox.Show("" + dd.Rows[0][1]); 

     ReportDataSource RDS = new ReportDataSource("Cars",dd); 


     RV.ProcessingMode = ProcessingMode.Local; 
     LocalReport lc = RV.LocalReport; 
     lc.DataSources.Add(RDS); 

     RV.LocalReport.ReportPath = "Report1.rdlc"; 

     this.RV.RefreshReport(); 

가 어떻게 보고서에 표시 할 데이터 테이블의 필드를 사용할 수의 ReportViewer에 통과?

답변

0

보고서 뷰어에 레코드를 바인딩하려면 Databind를 사용하십시오.

this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report1.rdlc"); 
ReportDataSource rds = new ReportDataSource("Cars", Dataset); 
this.ReportViewer1.ProcessingMode = ProcessingMode.Local 
this.ReportViewer1.LocalReport.DataSources.Clear(); 
this.ReportViewer1.LocalReport.DataSources.Add(rds); 
this.ReportViewer1.DataBind(); 
this.ReportViewer1.LocalReport.Refresh(); 

자세한 내용은 this codeproject 기사를 참조하십시오.

0

다음 단계를 따르십시오.

1) 프로젝트에 새 클래스 라이브러리 항목을 추가하십시오.

2)를 넣고 예와 같이,이 클래스의 속성으로 귀하의 데이터 테이블의 열을 정의

String _name; 
    Public String name 
    { 
     get {return _name;} 
     set {_name=Value;} 
    } 

3) 프로젝트를 빌드합니다.

4) 보고서 마법사 항목을 프로젝트에 추가하십시오.

5) 새 rdlc 보고서의 개체 유형으로 데이터 소스를 정의하고 클래스 (1 단계에서 정의)를 데이터 집합으로 선택합니다.

이제는 데이터 테이블의 열과 동일한 클래스 속성을 보고서의 필드로 볼 수 있습니다.

관련 문제