首页 > 其他 > 详细

Chart系列(二):数据绑定

时间:2014-11-07 23:18:07      阅读:521      评论:0      收藏:0      [点我收藏+]

1.绑定到OleDbDataReader:

// Define the database query    
string mySelectQuery="SELECT Name, Sales FROM REPS;";
// 。。。。。。
// Create a database reader    
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Since the reader implements and IEnumerable, pass the reader directly into
// the DataBindTable method with the name of the Column to be used as the XValue
Chart1.DataBindTable(myReader, "Name");

bubuko.com,布布扣

2.绑定DataSource

// Define the database query    
string mySelectQuery="SELECT * FROM REPS;";

// Create a database connection object using the connection string    
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
// Create a database command on the connection using query    
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
myConnection.Open();
// set chart data source - the data source must implement IEnumerable
chart1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Set series members names for the X and Y values 
chart1.Series["Series 1"].XValueMember = "Name";
chart1.Series["Series 1"].YValueMembers = "Sales";

// Data bind to the selected data source
chart1.DataBind();

bubuko.com,布布扣

3.绑定Y值

// Create a database reader    
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Since the reader implements and IEnumerable, pass the reader directly into
// the DataBind method with the name of the Column selected in the query    
chart1.Series["Default"].Points.DataBindY(myReader, "GrossSales");

bubuko.com,布布扣

4.绑定X和Y

// Create a database reader    
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Since the reader implements IEnumerable, pass the reader directly into
//   the DataBind method with the name of the Column selected in the query    
chart1.Series["Default"].Points.DataBindXY(myReader, "Name", myReader, "Sales");

bubuko.com,布布扣

Chart系列(二):数据绑定

原文:http://www.cnblogs.com/pengzhen/p/4082435.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!