转载:chart的数据库绑定,有一丢丢方法
但是还是有问题:“找不到名为 score 的列” ?
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ cmdText = String::Format("SELECT ID,课程号,学时 FROM 学生kcb");
Data::OleDb::OleDbCommand^ cmd = gcnew Data::OleDb::OleDbCommand(cmdText, oleDbConnection1);
OleDbDataAdapter^ da1 = gcnew OleDbDataAdapter(cmdText, oleDbConnection1);
DataTable^ table = gcnew DataTable;
da1->Fill(table);
chart1->DataSource = table->DefaultView;
// chart1->Series["Series1"]->DataBindTable(table,"ID");
//chart1->Series["Series1"]->Points->DataBindY = table;
chart1->DataBindCrossTable(table->DefaultView,"ID" , "课程号", "学时", "label=score");
//chart1->Series["Series1"]->Points->DataBind(table->DefaultView, "课程号", "学时", "Tooltip=Price{c1}");
// chart1->DataBind();
}