[英]How to Bind data to Pivot grid in Winforms using c# code in Winforms?
I wants to bind data to pivot grid using code not by SqlDataSource. 我想使用不是SqlDataSource的代码将数据绑定到数据透视表网格。
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
}
}
I have 5 Fields 我有5个领域
Name,Standard,City,Age,DobYear 名称,标准,城市,年龄,DobYear
I wants to set Name and City in row area , City in column area , Age and DobYear in data area 我要设置名称和市行区 , 市列区域 , 年龄和DobYear在数据区
Updated 更新
The above code is adding Name is Row field . 上面的代码添加了Name is Row字段 。 But not displaying records 但不显示记录
Try this : 尝试这个 :
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 });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.