C# 存储过程中的points.addxy

C# 存储过程中的points.addxy,c#,graphing,C#,Graphing,我正在尝试将结果返回到图表中并绘制它。我返回的数据库数据是一个datetime和一个float,因为它们都是对象,所以应该可以工作。我得到的错误是 无法从string转换为int 对于AddXY方法中的两个参数 string dateSelected = monthCalendarAdv1.Value.ToShortDateString(); dataConnection.Open(); SqlCommand dataCommand4 = new SqlCommand("SpTimeSerie

我正在尝试将结果返回到图表中并绘制它。我返回的数据库数据是一个datetime和一个float,因为它们都是对象,所以应该可以工作。我得到的错误是

无法从
string
转换为
int

对于
AddXY
方法中的两个参数

string dateSelected = monthCalendarAdv1.Value.ToShortDateString();
dataConnection.Open();

SqlCommand dataCommand4 = new SqlCommand("SpTimeSeriesTotalParity", dataConnection);
dataCommand4.Connection = dataConnection;
dataCommand4.CommandType = CommandType.StoredProcedure;
dataCommand4.Parameters.Add(new SqlParameter("@ValDate", dateSelected));
dataCommand4.Parameters.Add(new SqlParameter("@Acct", cmbSelectAccno.Text));

下面的代码与此类似,在处理第一个参数时没有任何问题

this.chart1.Series["$Parity"].Points.AddXY("Item1",1);
this.chart1.Series["$Parity"].Points.AddXY("Item2", 2); 
this.chart1.Series["$Parity"].Points.AddXY("Item3", 3); 
this.chart1.Series["$Parity"].Points.AddXY("Item4", 4); 
this.chart1.Series["$Parity"].Points.AddXY("Item5", 5); 

try
{
    dataConnection.Open();
    using (SqlDataReader myReader = dataCommand4.ExecuteReader())
                    // myReader = dataConnection.ExecuteReader();
       while (myReader.Read())
       {
           this.chart1.Series["$Parity"].Points.AddXY
              (myReader.GetDateTime("ValuationDate"), myReader.GetDouble("SumParity"));
       }
}

这里的问题不是addxy方法,而是命令读取器getter方法

两者都需要该列的基于0的索引,而不是它的名称

将代码更改为以下内容:

this.chart1.Series ["$Parity"].Points.AddXY (myReader.GetDateTime(2), myReader.GetDouble(3));

下面的代码与此类似,在处理第一个参数时没有任何问题。这个.chart1.系列[“$Parity”].Points.AddXY(“Item1”,1);这个.chart1.系列[“$Parity”].Points.AddXY(“Item2”,2);此.chart1.系列[“$Parity”].Points.AddXY(“Item3”,3);这个.chart1.系列[“$Parity”].Points.AddXY(“Item4”,4);这个.chart1.系列[“$Parity”].Points.AddXY(“Item5”,5);另外,语法C+C++ +FαVB VB公共对象int AddXY(对象xValm,PARAMS对象[y] yValue]参数xValpType:Stase.Object数据点的X值。Y值类型:System.Object[]一个oI已编辑您的标题。请参阅“”,其中的共识是“不,他们不应该”。