我正在嘗試向列表中添加值,但我一直收到錯誤「ArgumentOutOfRangeException」,我正在使用一個livecharts(圖表庫)。如何將值添加到C#中的列表
這裏是我的代碼:
string constring = "server=localhost;port=3306;username=root;password=root";
string Query = "SELECT Therapist, COUNT(*) AS magnitude FROM dbinfo.tblorder GROUP BY Therapist ORDER BY magnitude DESC";
MySqlConnection con = new MySqlConnection(constring);
MySqlCommand cmdDB = new MySqlCommand(Query, con);
MySqlDataReader myReader;
try
{
con.Open();
myReader = cmdDB.ExecuteReader();
while (myReader.Read())
{
int valuez = myReader.GetInt16("magnitude");
cartesianChart1.Series[1].Values.Add(valuez);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Data.con.Close();
cartesianChart1.Series = new SeriesCollection
{
new ColumnSeries
{
Title = "Therapist",
Values = new ChartValues<int> { 10, 50, 39, 50 }
}
};
cartesianChart1.AxisX.Add(new Axis
{
Title = "Therapists",
Labels = new[] { "Maria", "Susan", "Charles", "Frida" }
});
我會推薦使用輕量級的ORM,如[Dapper](https://github.com/StackExchange/Dapper)。 –
什麼行會拋出異常?什麼值「超出範圍」? –
對不起,它是從這個「cartesianChart1.Series [1] .Values.Add(valuez);」 – sakusa1