2017-08-14 4 views
0

Ich möchte Daten an Pivot-Raster mit Code nicht von SqlDataSource binden.Wie binden Sie Daten an Pivot-Raster in WinForms mit C# -Code in WinForms?

private void Report_Summary_Load(object sender,EventArgs e) 
{ 
    string cs= configuraitonManager.connectionString["connectionStringDatabase"].connectionString; 

    using(SqlConnection con = new SqlConnection(cs)) 
    { 
     SqlCommand cmd = new SqlCommand("spStoredProcedureTest",con); 
     cmd.CommandType = CommandType.StoredProcedure; 
     con.open(); 

     SqlDataReader sda = new SqlDataAdapter(cmd); 
     DataSet ds = new DataSet(); 
     sda.Fill(ds); 
     pivotGrid.DataSource = ds; 

     PivotGridField Name = new PivotGridField("Name",PivotArea.RowArea); 
     PivotGrid.Fields.AddRange(new PivotGridField[] {Name}); 

     Name.AreaIndex = 0; 

     // My pivot grid name is "pivotGridDemo" 

     //How to bind the data to the data area,column area and Row area 
    } 
} 

Ich habe 5 Felder

Namen, Standard, Stadt, Alter, DobYear

I Namen und Stadt in Zeilenbereich, Stadt in Spaltenbereich, setzen will Alter und DobYear in Datenbereich

Aktualisiert

Der oben genannte Code lautet . Name ist Row field. Aber nicht die Anzeige Aufzeichnungen

Antwort

1

Versuchen Sie folgendes:

pivotGrid.DataSource = ds.Tables[0]; 
PivotGridField fieldCity = new PivotGridField("City", PivotArea.ColumnArea); 
fieldCity.Caption = "City"; 

PivotGridField fieldName = new PivotGridField("Name", PivotArea.RowArea); 
fieldBureau.Caption = "Name"; 

PivotGridField fieldCity = new PivotGridField("City", PivotArea.RowArea); 
fieldBureau.Caption = "City"; 

PivotGridField fieldAge = new PivotGridField("Age", PivotArea.DataArea); 
fieldQte.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric; 
fieldAge.AreaIndex = 0; 
PivotGridField fieldDobYear = new PivotGridField("DobYear ", PivotArea.DataArea); 

    pivotGrid.Fields.AddRange(new PivotGridField[] { fieldCity, fieldName , fieldAge , fieldDobYear });