我正在尝试向列表中添加值,但我一直收到错误“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