首页 > 代码库 > Chart系列(二):数据绑定
Chart系列(二):数据绑定
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 XValueChart1.DataBindTable(myReader, "Name");
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 IEnumerablechart1.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 sourcechart1.DataBind();
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");
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");
Chart系列(二):数据绑定
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。